List of usage examples for junit.framework Assert assertNotNull
static public void assertNotNull(Object object)
From source file:com.taobao.ad.jpa.test.UUserTest.java
@Test public void testFindUUserXGroups() { Assert.assertNotNull(userBO.findUUserXGroups(1L)); }
From source file:com.taobao.ad.jpa.test.RepeatAlarmTest.java
@Test public void tesDeleteIfNumIsZero_just_jian1() { repeatAlarmBO.checkRepeatAlarm(5);// www. ja va 2 s .c om RepeatAlarmDO r = repeatAlarmBO.getRepeatAlarmById(5); Assert.assertNotNull(r); Assert.assertEquals(5, r.getId().intValue()); Assert.assertEquals("delete5", r.getJobName()); Assert.assertEquals("15", r.getJobGroup()); Assert.assertEquals(1111, r.getSignTime()); Assert.assertEquals(1, r.getRepeatAlarmNum()); Assert.assertEquals(1, r.getStatus().intValue()); }
From source file:org.mayocat.theme.ThemeDefinitionTest.java
@Test public void testParseTypes() throws Exception { String themeConfig = Resources.toString(Resources.getResource("theme-with-types.yml"), Charsets.UTF_8); ThemeDefinition theme = mapper.readValue(themeConfig, ThemeDefinition.class); Assert.assertTrue(theme.getProductTypes().size() > 0); TypeDefinition typeShirt = theme.getProductTypes().get("shirt"); Assert.assertNotNull(typeShirt); Assert.assertEquals("T-Shirt", typeShirt.getName()); FeatureDefinition colorFeature = typeShirt.getFeatures().get("color"); Assert.assertNotNull(colorFeature);// www .j a v a 2 s . c o m Assert.assertEquals("Color", colorFeature.getName()); Assert.assertEquals(0, colorFeature.getKeys().size()); Assert.assertEquals(0, colorFeature.getAddons().size()); FeatureDefinition sizeFeature = typeShirt.getFeatures().get("size"); Assert.assertNotNull(sizeFeature); Assert.assertEquals("Size", sizeFeature.getName()); Assert.assertEquals(3, sizeFeature.getKeys().size()); Assert.assertEquals(1, sizeFeature.getAddons().size()); VariantsDefinition variants = typeShirt.getVariants(); Assert.assertEquals(3, variants.getProperties().size()); Assert.assertEquals(1, variants.getAddons().size()); }
From source file:com.platform.middlewares.plugins.KVStorePlugin.java
@Override public boolean handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) {// w w w.ja v a 2s.c o m if (target.startsWith("/_kv/")) { Log.i(TAG, "handling: " + target + " " + baseRequest.getMethod()); String key = target.replace("/_kv/", ""); MainActivity app = MainActivity.app; if (app == null) { Log.e(TAG, "handle: context is null: " + target + " " + baseRequest.getMethod()); return BRHTTPHelper.handleError(500, "context is null", baseRequest, response); } if (key.isEmpty()) { Log.e(TAG, "handle: missing key argument: " + target + " " + baseRequest.getMethod()); return BRHTTPHelper.handleError(400, null, baseRequest, response); } RemoteKVStore remote = RemoteKVStore.getInstance(APIClient.getInstance(app)); ReplicatedKVStore store = new ReplicatedKVStore(app, remote); switch (request.getMethod()) { case "GET": Log.i(TAG, "handle: " + target + " " + baseRequest.getMethod() + ", key: " + key); CompletionObject getObj = store.get(key, 0); KVEntity kv = getObj.kv; if (kv == null) { Log.e(TAG, "handle: kv store does not contain the kv: " + key); return BRHTTPHelper.handleError(400, null, baseRequest, response); } byte[] decompressedData = BRCompressor.bz2Extract(kv.getValue()); Assert.assertNotNull(decompressedData); try { JSONObject test = new JSONObject(new String(decompressedData)); //just check for validity } catch (JSONException e) { e.printStackTrace(); Log.e(TAG, "handle: the json is not valid: " + target + " " + baseRequest.getMethod()); return BRHTTPHelper.handleError(500, null, baseRequest, response); } response.setHeader("ETag", String.valueOf(kv.getVersion())); SimpleDateFormat dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss:SSS Z", Locale.getDefault()); String date = dateFormat.format(kv.getTime()); response.setHeader("Last-Modified", date); if (kv.getDeleted() > 0) { Log.w(TAG, "handle: the key is gone: " + target + " " + baseRequest.getMethod()); return BRHTTPHelper.handleError(410, "Gone", baseRequest, response); } return BRHTTPHelper.handleSuccess(200, decompressedData, baseRequest, response, "application/json"); case "PUT": Log.i(TAG, "handle:" + target + " " + baseRequest.getMethod() + ", key: " + key); // Read from request byte[] rawData = null; try { InputStream body = request.getInputStream(); rawData = IOUtils.toByteArray(body); } catch (IOException e) { e.printStackTrace(); } if (rawData == null) { Log.e(TAG, "handle: missing request body: " + target + " " + baseRequest.getMethod()); return BRHTTPHelper.handleError(400, null, baseRequest, response); } String strVersion = request.getHeader("if-none-match"); if (strVersion == null) { Log.e(TAG, "handle: missing If-None-Match header, set to `0` if creating a new key: " + target + " " + baseRequest.getMethod()); return BRHTTPHelper.handleError(400, null, baseRequest, response); } String ct = request.getHeader("content-type"); if (ct == null || !ct.equalsIgnoreCase("application/json")) { Log.e(TAG, "handle: can only set application/json request bodies: " + target + " " + baseRequest.getMethod()); return BRHTTPHelper.handleError(400, null, baseRequest, response); } long version = Long.valueOf(strVersion); byte[] compressedData = BRCompressor.bz2Compress(rawData); assert (compressedData != null); CompletionObject setObj = store .set(new KVEntity(version, 0, key, compressedData, System.currentTimeMillis(), 0)); if (setObj.err != null) { Log.e(TAG, "handle: error setting the key: " + key + ", err: " + setObj.err); int errCode = transformErrorToResponseCode(setObj.err); return BRHTTPHelper.handleError(errCode, null, baseRequest, response); } response.setHeader("ETag", String.valueOf(setObj.version)); dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss:SSS Z", Locale.getDefault()); date = dateFormat.format(setObj.time); response.setHeader("Last-Modified", date); return BRHTTPHelper.handleSuccess(204, null, baseRequest, response, null); case "DELETE": Log.i(TAG, "handle: : " + target + " " + baseRequest.getMethod() + ", key: " + key); strVersion = request.getHeader("if-none-match"); Log.e(TAG, "handle: missing If-None-Match header: " + target + " " + baseRequest.getMethod()); if (strVersion == null) { return BRHTTPHelper.handleError(400, null, baseRequest, response); } CompletionObject delObj = null; try { delObj = store.delete(key, Long.parseLong(strVersion)); } catch (NumberFormatException e) { e.printStackTrace(); return BRHTTPHelper.handleError(500, null, baseRequest, response); } if (delObj == null || delObj.err != null) { int err = 500; if (delObj != null) { Log.e(TAG, "handle: error deleting key: " + key + ", err: " + delObj.err); err = transformErrorToResponseCode(delObj.err); } else { Log.e(TAG, "handle: error deleting key: " + key + ", delObj is null"); } return BRHTTPHelper.handleError(err, null, baseRequest, response); } response.setHeader("ETag", String.valueOf(delObj.version)); dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss:SSS Z", Locale.getDefault()); date = dateFormat.format(delObj.time); response.setHeader("Last-Modified", date); return BRHTTPHelper.handleSuccess(204, null, baseRequest, response, null); } } return false; }
From source file:net.idea.opentox.cli.test.DatasetClientTest.java
@Override public void testCreate() throws Exception { //in case the TEST_SERVER uses HTTP BASIC otclient.setHTTPBasicCredentials("localhost", 8080, "admin", "changeit"); DatasetClient<POLICY_RULE> cli = getOTClient(); URL url = getClass().getClassLoader().getResource("net/idea/opentox/cli/test/sdf/1000-90-4.sdf"); File fileToImport = new File(url.getFile()); Assert.assertTrue(fileToImport.exists()); Dataset dataset = new Dataset(); dataset.getMetadata().setTitle("Test dataset"); dataset.getMetadata().setSeeAlso("Test see also uri"); dataset.getMetadata()// w w w .jav a 2 s.c o m .setRights(new Rights("CC-BY-SA", "http://creativecommons.org/licenses/by-sa/2.0/", _type.license)); dataset.setInputData(new InputData(fileToImport, DatasetClient._MATCH.InChI)); RemoteTask task = cli.postAsync(dataset, new Identifier(String.format("%s%s", TEST_SERVER, Resources.dataset))); task.waitUntilCompleted(1000); //verify if ok Assert.assertEquals(HttpStatus.SC_OK, task.getStatus()); Assert.assertNull(task.getError()); List<Dataset> theDataset = cli.getMetadata(task.getResult()); Assert.assertEquals(1, theDataset.size()); Assert.assertEquals(dataset.getMetadata().getTitle(), theDataset.get(0).getMetadata().getTitle()); Assert.assertEquals(dataset.getMetadata().getSeeAlso(), theDataset.get(0).getMetadata().getSeeAlso()); Assert.assertEquals(task.getResult(), theDataset.get(0).getResourceIdentifier()); CompoundClient<POLICY_RULE> ccli = otclient.getCompoundClient(); List<Compound> compounds = cli.getCompounds(theDataset.get(0), ccli); Assert.assertNotNull(compounds); for (Compound compound : compounds) { System.out.println(compound); } //finally delete the dataset cli.delete(theDataset.get(0)); }
From source file:org.openmrs.module.idgen.service.IdentifierSourceServiceTest.java
/** * @see {@link IdentifierSourceService#getIdentifierSource(Integer)} *//*from w w w . j ava 2s . c o m*/ @Test @Verifies(value = "should return a saved remote identifier source", method = "getIdentifierSource(Integer)") public void getIdentifierSource_shouldReturnASavedRestIdentifierGenerator() throws Exception { RemoteIdentifierSource rig = (RemoteIdentifierSource) iss.getIdentifierSource(2); Assert.assertEquals(rig.getName(), "Test Remote Source"); Assert.assertNotNull(rig.getUrl()); }
From source file:io.cloudslang.lang.compiler.CompileResultsTest.java
private void testResults(String source, List<Result> expectedResults) throws Exception { Executable executable = preCompileExecutable(source); Assert.assertNotNull(executable); List<Result> actualResults = executable.getResults(); Assert.assertEquals(expectedResults, actualResults); }
From source file:org.openmrs.module.webservices.rest19ext.web.v1_0.controller.VisitAttributeControllerTest.java
@Test public void shouldAddAnAttributeToAVisit() throws Exception { int before = service.getVisitByUuid(Rest19ExtTestConstants.VISIT_UUID).getAttributes().size(); String json = "{\"attributeType\":\"6770f6d6-7673-11e0-8f03-001e378eb67g\", \"value\":\"2012-08-25\"}"; SimpleObject post = new ObjectMapper().readValue(json, SimpleObject.class); Object visitAttribute = controller.create(Rest19ExtTestConstants.VISIT_UUID, post, request, response); Assert.assertNotNull(visitAttribute); int after = service.getVisitByUuid(Rest19ExtTestConstants.VISIT_UUID).getAttributes().size(); Assert.assertEquals(before + 1, after); }
From source file:de.hybris.platform.servicelayer.media.impl.DefaultMediaPermissionServiceIntegrationTest.java
/** * //from ww w . j av a 2s . c om */ @Before public void setUp() throws Exception { final MediaFormatModel format = modelService.create(MediaFormatModel.class); format.setName("Format_abc"); format.setQualifier("format_abc"); modelService.save(format); final CatalogModel catalog = modelService.create(CatalogModel.class); catalog.setId("my_favorite_catalog"); modelService.save(catalog); catalogVersion = modelService.create(CatalogVersionModel.class); catalogVersion.setVersion("my_version"); catalogVersion.setCatalog(catalog); modelService.save(catalogVersion); final MediaContainerModel container = modelService.create(MediaContainerModel.class); container.setQualifier("test1234"); container.setCatalogVersion(this.catalogVersion); modelService.save(container); final String qualifier = "testMedia_" + format.getQualifier(); final MediaModel media = modelService.create(CatalogUnawareMediaModel.class); media.setCode(qualifier); media.setMediaFormat(format); media.setMediaContainer(container); this.modelService.save(media); testMediaItem = getMediaByFormat(container, format); Assert.assertNotNull(testMediaItem); permissionManagementService.createPermission(PermissionsConstants.READ); final UserModel user = userService.getCurrentUser(); final PermissionAssignment permissionAssignment = new PermissionAssignment(PermissionsConstants.READ, user); permissionManagementService.addItemPermission(testMediaItem, permissionAssignment); }
From source file:org.opencastproject.workspace.impl.WorkspaceImplTest.java
@Test public void testLongFilenames() throws Exception { WorkingFileRepository repo = EasyMock.createNiceMock(WorkingFileRepository.class); EasyMock.expect(repo.getBaseUri()).andReturn(new URI("http://localhost:8080/files")).anyTimes(); EasyMock.replay(repo);//from w ww .j a v a 2 s .c o m workspace.setRepository(repo); File source = new File( "target/test-classes/../test-classes/../test-classes/../test-classes/../test-classes/../test-classes/../test-classes/../test-classes/../test-classes/../test-classes/../test-classes/../test-classes/../test-classes/../test-classes/../test-classes/../test-classes/opencast_header.gif"); URL urlToSource = source.toURI().toURL(); TrustedHttpClient httpClient = EasyMock.createNiceMock(TrustedHttpClient.class); HttpEntity entity = EasyMock.createNiceMock(HttpEntity.class); EasyMock.expect(entity.getContent()).andReturn(new FileInputStream(source)); StatusLine statusLine = EasyMock.createNiceMock(StatusLine.class); EasyMock.expect(statusLine.getStatusCode()).andReturn(HttpServletResponse.SC_OK); HttpResponse response = EasyMock.createNiceMock(HttpResponse.class); EasyMock.expect(response.getEntity()).andReturn(entity); EasyMock.expect(response.getStatusLine()).andReturn(statusLine).anyTimes(); EasyMock.replay(response, entity, statusLine); EasyMock.expect(httpClient.execute((HttpUriRequest) EasyMock.anyObject())).andReturn(response); EasyMock.replay(httpClient); workspace.trustedHttpClient = httpClient; Assert.assertTrue(urlToSource.toString().length() > 255); try { Assert.assertNotNull(workspace.get(urlToSource.toURI())); } catch (NotFoundException e) { // This happens on some machines, so we catch and handle it. } }