List of usage examples for junit.framework Assert assertTrue
static public void assertTrue(String message, boolean condition)
From source file:com.sap.prd.mobile.ios.mios.DependencyToZipToCopyTest.java
@Test public void testPrepare() throws Exception { final String testName = getTestName(); final File testSourceDirApp = new File(getTestRootDirectory(), "straight-forward/MyApp"); final File alternateTestSourceDirApp = new File(getTestRootDirectory(), "straight-forward-transitive-bundles"); final File remoteRepositoryDirectory = getRemoteRepositoryDirectory(getClass().getName()); prepareRemoteRepository(remoteRepositoryDirectory); final File zipRepository = new File(new File(".").getCanonicalFile(), "src/test/zipRepository"); Properties pomReplacements = new Properties(); pomReplacements.setProperty(PROP_NAME_DEPLOY_REPO_DIR, remoteRepositoryDirectory.getAbsolutePath()); pomReplacements.setProperty(PROP_NAME_DYNAMIC_VERSION, "1.0." + String.valueOf(System.currentTimeMillis())); pomReplacements.setProperty(PROP_NAME_ZIP_REPO_DIR, zipRepository.getAbsolutePath()); final ProjectModifier projectModifier = new ChainProjectModifier( new FileCopyProjectModifier(alternateTestSourceDirApp, "pom.xml"), new ProjectModifier() { @Override/* w ww .j av a 2s.c o m*/ public void execute() throws Exception { final File pom = new File(testExecutionDirectory, "pom.xml"); FileInputStream fis = null; FileOutputStream fos = null; try { fis = new FileInputStream(pom); final Model model = new MavenXpp3Reader().read(fis); fis.close(); fos = new FileOutputStream(pom); Plugin plugin = model.getBuild().getPlugins().get(0); ((Xpp3Dom) plugin.getConfiguration()).getChild("additionalPackagingTypes") .getChild("html5").setValue("COPY"); new MavenXpp3Writer().write(fos, model); } finally { IOUtils.closeQuietly(fis); IOUtils.closeQuietly(fos); } } }); test(testName, testSourceDirApp, "com.sap.prd.mobile.ios.mios:xcode-maven-plugin:" + getMavenXcodePluginVersion() + ":prepare-xcode-build", THE_EMPTY_LIST, null, pomReplacements, projectModifier); File tmp = new File(getTestExecutionDirectory(testName, "MyApp"), "target/xcode-deps/html5/" + TestConstants.GROUP_ID + "/MyZip/MyZip-1.0.0.zip"); Assert.assertTrue("File '" + tmp + "' not found", tmp.exists()); File tmpWithDep = new File(getTestExecutionDirectory(testName, "MyApp"), "target/xcode-deps/html5/" + TestConstants.GROUP_ID + "/MyZipWithDep/MyZipWithDep-1.0.0.zip"); Assert.assertTrue("File '" + tmpWithDep + "' not found", tmpWithDep.exists()); }
From source file:org.wso2.carbon.esb.api.apidefinition.ESBJAVA4936SwaggerGenerationJsonYamlTestCase.java
@Test(groups = "wso2.esb", description = "Test API definition for Yaml is generated correctly") public void yamlDefinitionTest() throws Exception { String restURL = getMainSequenceURL() + "StockQuoteAPI?swagger.json"; SimpleHttpClient httpClient = new SimpleHttpClient(); HttpResponse response = httpClient.doGet(restURL, null); String payload = httpClient.getResponsePayload(response); log.info("Yaml Definition Response : " + payload); Assert.assertTrue("Swagger Yaml definition did not contained in the response", payload.contains("API Definition of StockQuoteAPI")); }
From source file:net.sf.dynamicreports.test.jasper.chart.GanttChartTest.java
@Override public void test() { super.test(); numberOfPagesTest(1);//www .j a v a 2 s . c o m JFreeChart chart = getChart("summary.chart1", 0); CategoryPlot categoryPlot = chart.getCategoryPlot(); Assert.assertEquals("renderer", GanttRenderer.class, categoryPlot.getRenderer().getClass()); Assert.assertTrue("show labels", categoryPlot.getRenderer().getBaseItemLabelsVisible()); Assert.assertFalse("show tick labels", categoryPlot.getDomainAxis().isTickMarksVisible()); Assert.assertFalse("show tick marks", categoryPlot.getDomainAxis().isTickLabelsVisible()); ganttChartDataTest(chart, "label", new String[] { "task1", "task2", "task3" }, new Object[][] { { toDate(2011, 1, 1), toDate(2011, 1, 8), 1d }, { toDate(2011, 1, 10), toDate(2011, 1, 15), 0.5d }, { toDate(2011, 1, 15), toDate(2011, 1, 25), 0.8d } }); ganttChartDataTest(chart, "serie1", new String[] { "task1", "task2", "task3" }, new Object[][] { { toDate(2011, 1, 2), toDate(2011, 1, 9), null }, { toDate(2011, 1, 8), toDate(2011, 1, 14), null }, { toDate(2011, 1, 16), toDate(2011, 1, 20), null } }); chart = getChart("summary.chart2", 0); Axis axis = chart.getCategoryPlot().getDomainAxis(); Assert.assertEquals("task label", "task", axis.getLabel()); Assert.assertEquals("task label color", Color.BLUE, axis.getLabelPaint()); Assert.assertEquals("task label font", new Font("Arial", Font.BOLD, 10), axis.getLabelFont()); Assert.assertEquals("tick label color", Color.CYAN, axis.getTickLabelPaint()); Assert.assertEquals("tick label font", new Font("Arial", Font.ITALIC, 10), axis.getTickLabelFont()); CategoryLabelPosition labelPosition = chart.getCategoryPlot().getDomainAxis().getCategoryLabelPositions() .getLabelPosition(RectangleEdge.LEFT); Assert.assertEquals("plot label rotation", (45d / 180) * Math.PI, labelPosition.getAngle()); Assert.assertEquals("line color", Color.LIGHT_GRAY, axis.getAxisLinePaint()); chart = getChart("summary.chart3", 0); axis = chart.getCategoryPlot().getRangeAxis(); Assert.assertEquals("time label", "time", axis.getLabel()); Assert.assertEquals("time label color", Color.BLUE, axis.getLabelPaint()); Assert.assertEquals("time label font", new Font("Arial", Font.BOLD, 10), axis.getLabelFont()); Assert.assertEquals("tick label color", Color.CYAN, axis.getTickLabelPaint()); Assert.assertEquals("tick label font", new Font("Arial", Font.ITALIC, 10), axis.getTickLabelFont()); Assert.assertEquals("line color", Color.LIGHT_GRAY, axis.getAxisLinePaint()); }
From source file:com.datatorrent.lib.io.fs.DirectoryScanInputOperatorTest.java
@SuppressWarnings({ "rawtypes", "unchecked" }) @Test/*from ww w .j ava 2s . c om*/ public void testDirectoryScan() throws InterruptedException, IOException { //Create the directory and the files used in the test case File baseDir = new File(dirName); // if the directory does not exist, create it if (!baseDir.exists()) { System.out.println("creating directory: " + dirName); boolean result = baseDir.mkdir(); if (result) { System.out.println("base directory created"); //create sub-directory File subDir = new File(dirName + "/subDir"); // if the directory does not exist, create it if (!subDir.exists()) { System.out.println("creating subdirectory: " + dirName + "/subDir"); boolean subDirResult = subDir.mkdir(); if (subDirResult) { System.out.println("sub directory created"); } } } else { System.out.println("Failed to create base directory"); return; } } //Create the files inside base dir int numOfFilesInBaseDir = 4; for (int num = 0; num < numOfFilesInBaseDir; num++) { String fileName = dirName + "/testFile" + String.valueOf(num + 1) + ".txt"; File file = new File(fileName); if (file.createNewFile()) { System.out.println(fileName + " is created!"); FileUtils.writeStringToFile(file, fileName); } else { System.out.println(fileName + " already exists."); } } //Create the files inside base subDir int numOfFilesInSubDir = 6; for (int num = 0; num < numOfFilesInSubDir; num++) { String fileName = dirName + "/subDir/testFile" + String.valueOf(num + numOfFilesInBaseDir + 1) + ".txt"; File file = new File(fileName); if (file.createNewFile()) { System.out.println(fileName + " is created!"); FileUtils.writeStringToFile(file, fileName); } else { System.out.println(fileName + " already exists."); } } DirectoryScanInputOperator oper = new DirectoryScanInputOperator(); oper.setDirectoryPath(dirName); oper.setScanIntervalInMilliSeconds(1000); oper.activate(null); CollectorTestSink sink = new CollectorTestSink(); oper.outport.setSink(sink); //Test if the existing files in the directory are emitted. Thread.sleep(1000); oper.emitTuples(); Assert.assertTrue("tuple emmitted: " + sink.collectedTuples.size(), sink.collectedTuples.size() > 0); Assert.assertEquals(sink.collectedTuples.size(), 10); //Test if the new file added is detected sink.collectedTuples.clear(); File oldFile = new File("../library/src/test/resources/directoryScanTestDirectory/testFile1.txt"); File newFile = new File("../library/src/test/resources/directoryScanTestDirectory/newFile.txt"); FileUtils.copyFile(oldFile, newFile); int timeoutMillis = 2000; while (sink.collectedTuples.isEmpty() && timeoutMillis > 0) { oper.emitTuples(); timeoutMillis -= 20; Thread.sleep(20); } Assert.assertTrue("tuple emmitted: " + sink.collectedTuples.size(), sink.collectedTuples.size() > 0); Assert.assertEquals(sink.collectedTuples.size(), 1); //clean up the directory to initial state newFile.delete(); oper.deactivate(); oper.teardown(); //clean up the directory used for the test FileUtils.deleteDirectory(baseDir); }
From source file:de.extrastandard.persistence.model.InputDataIT.java
@Test @Transactional// w ww . j a va 2 s.c o m public void testFindInputDataForExecutionWithResentWithLimit() { final Integer testDataSize = 6; for (Integer counter = 0; counter < testDataSize; counter++) { persistenceTestSetup.setUpTestDatenForFailProcedureSendFetchPhase3(); } final Integer inputDataLimit = 5; final List<ICommunicationProtocol> findInputDataForExecution = executionPersistence .findInputDataForExecutionWithResent(PersistenceTestSetup.PROCEDURE_DATA_MATCH_NAME, PhaseQualifier.PHASE3, inputDataLimit); Assert.assertTrue("Zu viele Daten ausgewhlt", findInputDataForExecution.size() <= inputDataLimit); final Set<Long> foundStatuses = new HashSet<Long>(); for (final ICommunicationProtocol communicationProtocol : findInputDataForExecution) { final Long phaseConnectionStatusId = communicationProtocol.getNextPhaseConnection().getStatus().getId(); final Set<Long> allowedStatuses = new HashSet<Long>(); allowedStatuses.add(PersistentStatus.INITIAL.getId()); allowedStatuses.add(PersistentStatus.FAIL.getId()); Assert.assertTrue("Unexpected Status", allowedStatuses.contains(phaseConnectionStatusId)); foundStatuses.add(phaseConnectionStatusId); } Assert.assertTrue("CommunicationProtocol for Resend not found", foundStatuses.contains(PersistentStatus.FAIL.getId())); }
From source file:org.xdi.oxauth.dev.TestSessionWorkflow.java
@Parameters({ "userId", "userSecret", "clientId", "clientSecret", "redirectUri" }) @Test//from w ww . j a v a 2s . c o m public void test(final String userId, final String userSecret, final String clientId, final String clientSecret, final String redirectUri) throws Exception { DefaultHttpClient httpClient = new DefaultHttpClient(); try { CookieStore cookieStore = new BasicCookieStore(); httpClient.setCookieStore(cookieStore); ClientExecutor clientExecutor = new ApacheHttpClient4Executor(httpClient); //////////////////////////////////////////////// // TV side. Code 1 // //////////////////////////////////////////////// AuthorizationRequest authorizationRequest1 = new AuthorizationRequest(Arrays.asList(ResponseType.CODE), clientId, Arrays.asList("openid", "profile", "email"), redirectUri, null); authorizationRequest1.setAuthUsername(userId); authorizationRequest1.setAuthPassword(userSecret); authorizationRequest1.getPrompts().add(Prompt.NONE); authorizationRequest1.setState("af0ifjsldkj"); authorizationRequest1.setRequestSessionId(true); AuthorizeClient authorizeClient1 = new AuthorizeClient(authorizationEndpoint); authorizeClient1.setRequest(authorizationRequest1); AuthorizationResponse authorizationResponse1 = authorizeClient1.exec(clientExecutor); // showClient(authorizeClient1, cookieStore); String code1 = authorizationResponse1.getCode(); String sessionId = authorizationResponse1.getSessionId(); Assert.assertNotNull("code1 is null", code1); Assert.assertNotNull("sessionId is null", sessionId); // TV sends the code to the Backend // We don't use httpClient and cookieStore during this call //////////////////////////////////////////////// // Backend 1 side. Code 1 // //////////////////////////////////////////////// // Get the access token TokenClient tokenClient1 = new TokenClient(tokenEndpoint); TokenResponse tokenResponse1 = tokenClient1.execAuthorizationCode(code1, redirectUri, clientId, clientSecret); String accessToken1 = tokenResponse1.getAccessToken(); Assert.assertNotNull("accessToken1 is null", accessToken1); // Get the user's claims UserInfoClient userInfoClient1 = new UserInfoClient(userInfoEndpoint); UserInfoResponse userInfoResponse1 = userInfoClient1.execUserInfo(accessToken1); Assert.assertTrue("userInfoResponse1.getStatus() is not 200", userInfoResponse1.getStatus() == 200); // System.out.println(userInfoResponse1.getEntity()); //////////////////////////////////////////////// // TV side. Code 2 // //////////////////////////////////////////////// AuthorizationRequest authorizationRequest2 = new AuthorizationRequest(Arrays.asList(ResponseType.CODE), clientId, Arrays.asList("openid", "profile", "email"), redirectUri, null); authorizationRequest2.getPrompts().add(Prompt.NONE); authorizationRequest2.setState("af0ifjsldkj"); authorizationRequest2.setSessionId(sessionId); AuthorizeClient authorizeClient2 = new AuthorizeClient(authorizationEndpoint); authorizeClient2.setRequest(authorizationRequest2); AuthorizationResponse authorizationResponse2 = authorizeClient2.exec(clientExecutor); // showClient(authorizeClient2, cookieStore); String code2 = authorizationResponse2.getCode(); Assert.assertNotNull("code2 is null", code2); // TV sends the code to the Backend // We don't use httpClient and cookieStore during this call //////////////////////////////////////////////// // Backend 2 side. Code 2 // //////////////////////////////////////////////// // Get the access token TokenClient tokenClient2 = new TokenClient(tokenEndpoint); TokenResponse tokenResponse2 = tokenClient2.execAuthorizationCode(code2, redirectUri, clientId, clientSecret); String accessToken2 = tokenResponse2.getAccessToken(); Assert.assertNotNull("accessToken2 is null", accessToken2); // Get the user's claims UserInfoClient userInfoClient2 = new UserInfoClient(userInfoEndpoint); UserInfoResponse userInfoResponse2 = userInfoClient2.execUserInfo(accessToken2); Assert.assertTrue("userInfoResponse1.getStatus() is not 200", userInfoResponse2.getStatus() == 200); // System.out.println(userInfoResponse2.getEntity()); } finally { if (httpClient != null) { httpClient.getConnectionManager().shutdown(); } } }
From source file:eu.stratosphere.pact.runtime.task.CrossTaskExternalITCase.java
@Test public void testExternalStreamCrossTask() { int keyCnt1 = 2; int valCnt1 = 1; // 87381 fit into memory, 87382 do not! int keyCnt2 = 87385; int valCnt2 = 1; super.initEnvironment(1 * 1024 * 1024); super.addInput(new UniformPactRecordGenerator(keyCnt1, valCnt1, false), 1); super.addInput(new UniformPactRecordGenerator(keyCnt2, valCnt2, false), 2); super.addOutput(this.outList); CrossTask<PactRecord, PactRecord, PactRecord> testTask = new CrossTask<PactRecord, PactRecord, PactRecord>(); super.getTaskConfig().setLocalStrategy(LocalStrategy.NESTEDLOOP_STREAMED_OUTER_FIRST); super.getTaskConfig().setMemorySize(1 * 1024 * 1024); super.registerTask(testTask, MockCrossStub.class); try {// w w w . j a v a2s . c o m testTask.invoke(); } catch (Exception e) { LOG.debug(e); Assert.fail("Invoke method caused exception."); } int expCnt = keyCnt1 * valCnt1 * keyCnt2 * valCnt2; Assert.assertTrue("Resultset size was " + this.outList.size() + ". Expected was " + expCnt, this.outList.size() == expCnt); this.outList.clear(); }
From source file:com.datatorrent.lib.io.HttpInputOperatorTest.java
@SuppressWarnings({ "rawtypes", "unchecked" }) @Test/*from w w w.j a v a 2s.c o m*/ public void testHttpInputModule() throws Exception { final List<String> receivedMessages = new ArrayList<String>(); Handler handler = new AbstractHandler() { int responseCount = 0; @Override public void handle(String string, Request rq, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); IOUtils.copy(request.getInputStream(), bos); receivedMessages.add(new String(bos.toByteArray())); response.setContentType("application/json"); response.setStatus(HttpServletResponse.SC_OK); response.setHeader("Transfer-Encoding", "chunked"); try { JSONObject json = new JSONObject(); json.put("responseId", "response" + ++responseCount); byte[] bytes = json.toString().getBytes(); response.getOutputStream().println(bytes.length); response.getOutputStream().write(bytes); response.getOutputStream().println(); response.getOutputStream().println(0); response.getOutputStream().flush(); } catch (JSONException e) { response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Error generating response: " + e.toString()); } ((Request) request).setHandled(true); } }; Server server = new Server(0); server.setHandler(handler); server.start(); String url = "http://localhost:" + server.getConnectors()[0].getLocalPort() + "/somecontext"; System.out.println(url); final AbstractHttpInputOperator operator = new HttpJsonChunksInputOperator(); CollectorTestSink sink = new CollectorTestSink(); operator.outputPort.setSink(sink); operator.setName("testHttpInputNode"); operator.setUrl(new URI(url)); operator.setup(null); operator.activate(null); int timeoutMillis = 3000; while (sink.collectedTuples.isEmpty() && timeoutMillis > 0) { operator.emitTuples(); timeoutMillis -= 20; Thread.sleep(20); } Assert.assertTrue("tuple emmitted", sink.collectedTuples.size() > 0); Map<String, String> tuple = (Map<String, String>) sink.collectedTuples.get(0); Assert.assertEquals("", tuple.get("responseId"), "response1"); operator.deactivate(); operator.teardown(); server.stop(); }
From source file:org.thingsplode.server.executors.ExecutorTest.java
@Before public void setupTest() throws UnknownHostException, SrvExecutionException { deviceService.setEnableAutoRegistration(true); if (testDevice == null || testDevice.getId() == null) { testDevice = deviceRepo.findByIdentification(testDeviceID); if (testDevice == null) { testDevice = TestFactory.createDevice(testDeviceID, "123456789", "1"); testDevice = deviceService.registerOrUpdate(testDevice); Assert.assertTrue("deletable_config should exists", testDevice.getConfigurationByKey("deletable_config") != null); Assert.assertTrue("the shutdown_timeout should be " + TestFactory.DEFAULT_SHUTDOWN_TIMEOUT, testDevice.getConfigurationByKey("shutdown_timeout").getValue() .equalsIgnoreCase(TestFactory.DEFAULT_SHUTDOWN_TIMEOUT)); }/*from w w w. j ava 2 s. co m*/ } }
From source file:org.thingsplode.server.repositories.RepositoryTest.java
@Test @Transactional//from w w w .ja va 2 s . c o m public void test2Events() throws UnknownHostException { String deviceID = "test_device_1"; String serialNumber = "12345"; deviceRepo.save(TestFactory.createDevice(deviceID, serialNumber, "1")); Device d = deviceRepo.findByIdentification(deviceID); Assert.assertTrue("The serial number should match", serialNumber.equalsIgnoreCase(d.getSerialNumber())); Assert.assertTrue("The version should be 1", "1".equalsIgnoreCase(d.getModel().getVersion())); d.getModel().setVersion("2"); deviceRepo.save(d); d = deviceRepo.findByIdentification(deviceID); Assert.assertTrue("The version should be 2", "2".equalsIgnoreCase(d.getModel().getVersion())); Assert.assertNotNull("The device id shall not be null at this stage", d.getId()); for (int i = 1; i <= 100; i++) { Event devt = Event .create("some-special-event", "some-special-event-class", Event.EventType.STATE_UPDATE, Event.Severity.INFO, Calendar.getInstance()) .putComponent(d).putReceiveDate(Calendar.getInstance()) .addIndication("peak", Value.Type.NUMBER, Integer.toString(i)); Event cevt = Event .create("a component event", "comp event class", Event.EventType.STATE_UPDATE, Event.Severity.ERROR, Calendar.getInstance()) .putComponent((Component) d.getComponents().toArray()[0]).putReceiveDate(Calendar.getInstance()) .addIndication("peak", Value.Type.TEXT, "componnent indication"); eventRepo.save(devt); eventRepo.save(cevt); } int evtCount = (int) eventRepo.count(); Assert.assertTrue("There should be 200 device events in the database at this stage, but there were: " + evtCount + ".", evtCount == 200); Page<Event> deviceEvtPage = eventRepo.findByComponent(d, new PageRequest(0, 300)); int deviceEvtCount = deviceEvtPage.getContent().size(); Assert.assertTrue("there should be 100 device events instead of [" + deviceEvtCount + "]", deviceEvtCount == 100); eventRepo.deleteAll(); deviceRepo.delete(d); deviceAssertions(0); }