List of usage examples for junit.framework Assert assertTrue
static public void assertTrue(String message, boolean condition)
From source file:at.tfr.securefs.ui.CopyFilesTest.java
@Test public void testCopyFilesByWalk() throws Exception { // Given: NO target directory yet!!, the source file final String data = "Hallo Echo"; try (OutputStream os = cp.getEncrypter(fromFile)) { IOUtils.write(data, os);/*from ww w .j a v a 2 s . c o m*/ } Assert.assertFalse(Files.exists(toRoot.resolve(DATA_FILES))); Assert.assertFalse(Files.exists(targetToFile)); // When: copy of fromRoot to toRoot ProcessFiles pf = new ProcessFilesBean(new MockSecureFsCache()); CopyFilesServiceBean cfb = new CopyFilesServiceBean(config, cp, pf, new MockSecureFsCache(), async); cfb.setFromPathName(fromRoot.toString()); cfb.setToPathName(toRoot.toString()); cfb.setNewSecret(newSecret); cfb.runCopyFiles(); // Then: a target file is created in same subpath like sourceFile: Assert.assertTrue("subpath is not created", Files.exists(toRoot.resolve(DATA_FILES))); Assert.assertTrue("target file not created", Files.exists(targetToFile)); // Then: the content of target file is decryptable with newSecret // and equals content of source file byte[] buf = new byte[data.getBytes().length]; try (InputStream is = cp.getDecrypter(targetToFile, newSecret)) { IOUtils.read(is, buf); } Assert.assertEquals("failed to decrypt data", data, String.valueOf(data)); }
From source file:com.espertech.esper.multithread.StmtMgmtCallable.java
public Object call() throws Exception { try {//from www . j a v a2s. c o m for (int loop = 0; loop < numRepeats; loop++) { for (Object[] statement : statements) { boolean isEPL = (Boolean) statement[0]; String statementText = (String) statement[1]; // Create EPL or pattern statement EPStatement stmt; ThreadLogUtil.trace("stmt create,", statementText); if (isEPL) { stmt = engine.getEPAdministrator().createEPL(statementText); } else { stmt = engine.getEPAdministrator().createPattern(statementText); } ThreadLogUtil.trace("stmt done,", stmt); // Add listener SupportMTUpdateListener listener = new SupportMTUpdateListener(); LogUpdateListener logListener; if (isEPL) { logListener = new LogUpdateListener(null); } else { logListener = new LogUpdateListener("a"); } ThreadLogUtil.trace("adding listeners ", listener, logListener); stmt.addListener(listener); stmt.addListener(logListener); Object theEvent = makeEvent(); ThreadLogUtil.trace("sending event ", theEvent); engine.getEPRuntime().sendEvent(theEvent); // Should have received one or more events, one of them must be mine EventBean[] newEvents = listener.getNewDataListFlattened(); Assert.assertTrue("No event received", newEvents.length >= 1); ThreadLogUtil.trace("assert received, size is", newEvents.length); boolean found = false; for (int i = 0; i < newEvents.length; i++) { Object underlying = newEvents[i].getUnderlying(); if (!isEPL) { underlying = newEvents[i].get("a"); } if (underlying == theEvent) { found = true; } } Assert.assertTrue(found); listener.reset(); // Stopping statement, the event should not be received, another event may however ThreadLogUtil.trace("stop statement"); stmt.stop(); theEvent = makeEvent(); ThreadLogUtil.trace("send non-matching event ", theEvent); engine.getEPRuntime().sendEvent(theEvent); // Make sure the event was not received newEvents = listener.getNewDataListFlattened(); found = false; for (int i = 0; i < newEvents.length; i++) { Object underlying = newEvents[i].getUnderlying(); if (!isEPL) { underlying = newEvents[i].get("a"); } if (underlying == theEvent) { found = true; } } Assert.assertFalse(found); } } } catch (AssertionFailedError ex) { log.fatal("Assertion error in thread " + Thread.currentThread().getId(), ex); return false; } catch (Exception ex) { log.fatal("Error in thread " + Thread.currentThread().getId(), ex); return false; } return true; }
From source file:com.btobits.automator.fix.ant.task.FixDisconnectExpect.java
@Override protected void runTestInstructions() throws Exception { Assert.assertTrue("FIX session with parameters [" + fixSession.getSessionID() + "] is not active", FixConnectivity.isSessionActive(fixSession.getSessionID())); conn.addConnectionListener(this); startTime = System.nanoTime(); }
From source file:eu.stratosphere.pact.runtime.task.CombineTaskTest.java
@Test public void testCombineTask() { int keyCnt = 100; int valCnt = 20; super.initEnvironment(3 * 1024 * 1024); super.addInput(new UniformPactRecordGenerator(keyCnt, valCnt, false), 1); super.addOutput(this.outList); CombineTask<PactRecord> testTask = new CombineTask<PactRecord>(); super.getTaskConfig().setLocalStrategy(LocalStrategy.COMBININGSORT); super.getTaskConfig().setMemorySize(3 * 1024 * 1024); super.getTaskConfig().setNumFilehandles(2); final int[] keyPos = new int[] { 0 }; @SuppressWarnings("unchecked") final Class<? extends Key>[] keyClasses = (Class<? extends Key>[]) new Class[] { PactInteger.class }; PactRecordComparatorFactory.writeComparatorSetupToConfig(super.getTaskConfig().getConfiguration(), super.getTaskConfig().getPrefixForInputParameters(0), keyPos, keyClasses); super.registerTask(testTask, MockCombiningReduceStub.class); try {// w ww . j a va 2 s . c om testTask.invoke(); } catch (Exception e) { LOG.debug(e); Assert.fail("Invoke method caused exception."); } int expSum = 0; for (int i = 1; i < valCnt; i++) { expSum += i; } Assert.assertTrue("Resultset size was " + this.outList.size() + ". Expected was " + keyCnt, this.outList.size() == keyCnt); for (PactRecord record : this.outList) { Assert.assertTrue("Incorrect result", record.getField(1, PactInteger.class).getValue() == expSum); } this.outList.clear(); }
From source file:eu.stratosphere.pact.runtime.task.DataSinkTaskTest.java
@Test public void testDataSinkTask() { int keyCnt = 100; int valCnt = 20; super.initEnvironment(MEMORY_MANAGER_SIZE, NETWORK_BUFFER_SIZE); super.addInput(new UniformRecordGenerator(keyCnt, valCnt, false), 0); DataSinkTask<Record> testTask = new DataSinkTask<Record>(); super.registerFileOutputTask(testTask, MockOutputFormat.class, new File(tempTestPath).toURI().toString()); try {//from w w w . ja v a 2 s . c o m testTask.invoke(); } catch (Exception e) { LOG.debug(e); Assert.fail("Invoke method caused exception."); } File tempTestFile = new File(this.tempTestPath); Assert.assertTrue("Temp output file does not exist", tempTestFile.exists()); FileReader fr = null; BufferedReader br = null; try { fr = new FileReader(tempTestFile); br = new BufferedReader(fr); HashMap<Integer, HashSet<Integer>> keyValueCountMap = new HashMap<Integer, HashSet<Integer>>(keyCnt); while (br.ready()) { String line = br.readLine(); Integer key = Integer.parseInt(line.substring(0, line.indexOf("_"))); Integer val = Integer.parseInt(line.substring(line.indexOf("_") + 1, line.length())); if (!keyValueCountMap.containsKey(key)) { keyValueCountMap.put(key, new HashSet<Integer>()); } keyValueCountMap.get(key).add(val); } Assert.assertTrue("Invalid key count in out file. Expected: " + keyCnt + " Actual: " + keyValueCountMap.keySet().size(), keyValueCountMap.keySet().size() == keyCnt); for (Integer key : keyValueCountMap.keySet()) { Assert.assertTrue("Invalid value count for key: " + key + ". Expected: " + valCnt + " Actual: " + keyValueCountMap.get(key).size(), keyValueCountMap.get(key).size() == valCnt); } } catch (FileNotFoundException e) { Assert.fail("Out file got lost..."); } catch (IOException ioe) { Assert.fail("Caught IOE while reading out file"); } finally { if (br != null) { try { br.close(); } catch (Throwable t) { } } if (fr != null) { try { fr.close(); } catch (Throwable t) { } } } }
From source file:eu.stratosphere.pact.runtime.task.ReduceTaskTest.java
@Test public void testReduceTaskWithSortingInput() { final int keyCnt = 100; final int valCnt = 20; addInputComparator(this.comparator); setOutput(this.outList); getTaskConfig().setDriverStrategy(DriverStrategy.SORTED_GROUP_REDUCE); try {/*from w w w . j a v a 2 s . c o m*/ addInputSorted(new UniformRecordGenerator(keyCnt, valCnt, false), this.comparator.duplicate()); GroupReduceDriver<Record, Record> testTask = new GroupReduceDriver<Record, Record>(); testDriver(testTask, MockReduceStub.class); } catch (Exception e) { LOG.debug(e); Assert.fail("Exception in Test."); } Assert.assertTrue("Resultset size was " + this.outList.size() + ". Expected was " + keyCnt, this.outList.size() == keyCnt); for (Record record : this.outList) { Assert.assertTrue("Incorrect result", record.getField(1, IntValue.class).getValue() == valCnt - record.getField(0, IntValue.class).getValue()); } this.outList.clear(); }
From source file:eu.stratosphere.pact.runtime.task.MatchTaskExternalITCase.java
@Test public void testExternalSort1MatchTask() { int keyCnt1 = 16384 * 2; int valCnt1 = 2; int keyCnt2 = 8192; int valCnt2 = 4 * 2; super.initEnvironment(6 * 1024 * 1024); super.addInput(new UniformPactRecordGenerator(keyCnt1, valCnt1, false), 1); super.addInput(new UniformPactRecordGenerator(keyCnt2, valCnt2, false), 2); super.addOutput(this.outList); final MatchTask<PactRecord, PactRecord, PactRecord> testTask = new MatchTask<PactRecord, PactRecord, PactRecord>(); super.getTaskConfig().setLocalStrategy(LocalStrategy.SORT_BOTH_MERGE); super.getTaskConfig().setMemorySize(6 * 1024 * 1024); super.getTaskConfig().setNumFilehandles(4); final int[] keyPos1 = new int[] { 0 }; final int[] keyPos2 = new int[] { 0 }; @SuppressWarnings("unchecked") final Class<? extends Key>[] keyClasses = (Class<? extends Key>[]) new Class[] { PactInteger.class }; PactRecordComparatorFactory.writeComparatorSetupToConfig(super.getTaskConfig().getConfiguration(), super.getTaskConfig().getPrefixForInputParameters(0), keyPos1, keyClasses); PactRecordComparatorFactory.writeComparatorSetupToConfig(super.getTaskConfig().getConfiguration(), super.getTaskConfig().getPrefixForInputParameters(1), keyPos2, keyClasses); super.registerTask(testTask, MockMatchStub.class); try {/*from w ww . j a va 2s. c o m*/ testTask.invoke(); } catch (Exception e) { LOG.debug(e); Assert.fail("Invoke method caused exception."); } int expCnt = valCnt1 * valCnt2 * Math.min(keyCnt1, keyCnt2); Assert.assertTrue("Resultset size was " + this.outList.size() + ". Expected was " + expCnt, this.outList.size() == expCnt); this.outList.clear(); }
From source file:com.rmn.qa.aws.VmManagerTest.java
@Test // Test if an AWS private key is not set, the appropriate exception if thrown public void testPrivateKeyNotSet() { MockAmazonEc2Client client = new MockAmazonEc2Client(null); Properties properties = new Properties(); properties.setProperty(AutomationConstants.AWS_ACCESS_KEY, "foo"); String region = "east"; AwsVmManager AwsVmManager = new AwsVmManager(client, properties, region); try {//from ww w. j a va2 s. com AwsVmManager.getCredentials(); } catch (IllegalArgumentException e) { Assert.assertTrue("Message should be related to access key: " + e.getMessage(), e.getMessage().contains(AutomationConstants.AWS_PRIVATE_KEY)); return; } Assert.fail("Exception should have been throw for access key"); }
From source file:com.thoughtworks.acceptance.EncodingTestSuite.java
private void test(final HierarchicalStreamDriver driver, final String encoding) throws IOException { final String headerLine = encoding != null ? "<?xml version=\"1.0\" encoding=\"" + encoding + "\"?>\n" : ""; final String xmlData = headerLine // force code format + "<test>\n" + " <data>J\u00f6rg</data>\n" + "</test>"; final XStream xstream = new XStream(driver); xstream.allowTypes(TestObject.class); xstream.alias("test", TestObject.class); final TestObject obj = new TestObject(); obj.data = "J\u00f6rg"; final ByteArrayOutputStream bos = new ByteArrayOutputStream(); final OutputStreamWriter writer = encoding != null ? new OutputStreamWriter(bos, encoding) : new OutputStreamWriter(bos); xstream.toXML(obj, writer);/*ww w . j a v a2 s . c o m*/ writer.close(); final String generated = encoding != null ? bos.toString(encoding) : bos.toString(); Assert.assertTrue("'" + obj.data + "' was not found", generated.indexOf(obj.data) > 0); final Object restored = xstream.fromXML( new ByteArrayInputStream(encoding != null ? xmlData.getBytes(encoding) : xmlData.getBytes())); Assert.assertEquals(obj, restored); }
From source file:de.unentscheidbar.validation.DefaultMessageTextGetterTest.java
@Test public void testDefaultMessageTexts() { Locale[] locales = { Locale.ROOT, Locale.GERMAN }; Reflections r = new Reflections(new ConfigurationBuilder() .setUrls(ClasspathHelper.forPackage(ClassUtils.getPackageName(Validators.class))) .setScanners(new ResourcesScanner(), new SubTypesScanner(false))); Collection<Class<? extends Id>> defaultMessageClasses = Collections2.filter( r.getSubTypesOf(ValidationMessage.Id.class), Predicates.and(IS_NOT_ABSTRACT, IsTestClass.NO)); Assert.assertTrue("Suspiciously few message ID classes found", defaultMessageClasses.size() > 10); MessageTextGetter mtg = Validation.defaultMessageTextGetter(); for (Class<? extends Id> idClass : defaultMessageClasses) { /* only works with enums atm (all default message ids are enums) */ if (!idClass.isEnum()) { Assert.fail("Cannot test " + idClass.getName()); }/*from w w w .ja v a 2s . c o m*/ for (Id id : idClass.getEnumConstants()) { for (Locale locale : locales) { Assert.assertTrue("Missing default message text for " + locale + " -> " + id.getClass().getName() + " -> " + id.name(), mtg.hasText(id, locale)); } } } }