@Test public void testEncodeResourceRef() throws DataFormatException { Patient patient = new Patient(); patient.setManagingOrganization(new ResourceReferenceDt()); IParser p = ourCtx.newXmlParser(); String str = p.encodeResourceToString(patient); assertThat(str, IsNot.not(StringContains.containsString("managingOrganization"))); ResourceReferenceDt ref = new ResourceReferenceDt(); ref.setReference("Organization/123"); ref.setDisplay("DISPLAY!"); patient.setManagingOrganization(ref); str = p.encodeResourceToString(patient); assertThat(str, StringContains.containsString("<managingOrganization><reference value=\"Organization/123\"/><display value=\"DISPLAY!\"/></managingOrganization>")); Organization org = new Organization(); org.addIdentifier().setSystem("foo").setValue("bar"); patient.setManagingOrganization(new ResourceReferenceDt(org)); str = p.encodeResourceToString(patient); assertThat(str, StringContains.containsString("<contained><Organization")); }
@Test public void testEncodeContainedResourcesMore() { DiagnosticReport rpt = new DiagnosticReport(); Specimen spm = new Specimen(); rpt.getText().setDiv("AAA"); rpt.addSpecimen().setResource(spm); IParser p = new FhirContext(DiagnosticReport.class).newJsonParser().setPrettyPrint(true); String str = p.encodeResourceToString(rpt); ourLog.info(str); assertThat(str, StringContains.containsString("<div>AAA</div>")); String substring = "\"reference\":\"#"; assertThat(str, StringContains.containsString(substring)); int idx = str.indexOf(substring) + substring.length(); int idx2 = str.indexOf('"', idx + 1); String id = str.substring(idx, idx2); assertThat(str, StringContains.containsString("\"id\":\"" + id + "\"")); assertThat(str, IsNot.not(StringContains.containsString("<?xml version='1.0'?>"))); }
@Test public void testEncodeResourceRef() throws DataFormatException { Patient patient = new Patient(); patient.setManagingOrganization(new ResourceReferenceDt()); IParser p = new FhirContext().newJsonParser(); String str = p.encodeResourceToString(patient); assertThat(str, IsNot.not(StringContains.containsString("managingOrganization"))); patient.setManagingOrganization(new ResourceReferenceDt("Organization/123")); str = p.encodeResourceToString(patient); assertThat(str, StringContains.containsString("\"managingOrganization\":{\"reference\":\"Organization/123\"}")); Organization org = new Organization(); org.addIdentifier().setSystem("foo").setValue("bar"); patient.setManagingOrganization(new ResourceReferenceDt(org)); str = p.encodeResourceToString(patient); assertThat(str, StringContains.containsString("\"contained\":[{\"resourceType\":\"Organization\"")); }
@Test public void testEncodeContainedResources() throws Exception { DiagnosticReport rpt = new DiagnosticReport(); Specimen spm = new Specimen(); spm.addIdentifier().setSystem("urn").setValue( "123"); rpt.getText().setDivAsString("AAA"); rpt.addSpecimen().setResource(spm); IParser p = ourCtx.newXmlParser().setPrettyPrint(true); String str = p.encodeResourceToString(rpt); ourLog.info(str); assertThat(str, StringContains.containsString("<div xmlns=\"http://www.w3.org/1999/xhtml\">AAA</div>")); assertThat(str, StringContains.containsString("reference value=\"#")); int idx = str.indexOf("reference value=\"#") + "reference value=\"#".length(); int idx2 = str.indexOf('"', idx + 1); String id = str.substring(idx, idx2); assertThat(str, StringContains.containsString("<Specimen xmlns=\"http://hl7.org/fhir\" id=\"" + id + "\">")); assertThat(str, IsNot.not(StringContains.containsString("<?xml version='1.0'?>"))); }
@Test public void testEncodeResourceRef() throws DataFormatException { Patient patient = new Patient(); patient.setManagingOrganization(new Reference()); IParser p = ourCtx.newXmlParser(); String str = p.encodeResourceToString(patient); assertThat(str, IsNot.not(StringContains.containsString("managingOrganization"))); Reference ref = new Reference(); ref.setReference("Organization/123"); ref.setDisplay("DISPLAY!"); patient.setManagingOrganization(ref); str = p.encodeResourceToString(patient); assertThat(str, StringContains.containsString("<managingOrganization><reference value=\"Organization/123\"/><display value=\"DISPLAY!\"/></managingOrganization>")); Organization org = new Organization(); org.addIdentifier().setSystem("foo").setValue("bar"); patient.setManagingOrganization(new Reference(org)); str = p.encodeResourceToString(patient); assertThat(str, StringContains.containsString("<contained><Organization")); }
@Test public void testEncodeContainedResourcesMore() throws Exception { DiagnosticReport rpt = new DiagnosticReport(); Specimen spm = new Specimen(); rpt.getText().setDivAsString("AAA"); rpt.addSpecimen().setResource(spm); IParser p = new FhirContext(DiagnosticReport.class).newJsonParser().setPrettyPrint(true); String str = p.encodeResourceToString(rpt); ourLog.info(str); assertThat(str, StringContains.containsString("<div>AAA</div>")); String substring = "\"reference\":\"#"; assertThat(str, StringContains.containsString(substring)); int idx = str.indexOf(substring) + substring.length(); int idx2 = str.indexOf('"', idx + 1); String id = str.substring(idx, idx2); assertThat(str, StringContains.containsString("\"id\":\"" + id + "\"")); assertThat(str, IsNot.not(StringContains.containsString("<?xml version='1.0'?>"))); }
@Test public void testEncodeResourceRef() throws DataFormatException { Patient patient = new Patient(); patient.setManagingOrganization(new Reference()); IParser p = new FhirContext().newJsonParser(); String str = p.encodeResourceToString(patient); assertThat(str, IsNot.not(StringContains.containsString("managingOrganization"))); patient.setManagingOrganization(new Reference("Organization/123")); str = p.encodeResourceToString(patient); assertThat(str, StringContains.containsString("\"managingOrganization\":{\"reference\":\"Organization/123\"}")); Organization org = new Organization(); org.addIdentifier().setSystem("foo").setValue("bar"); patient.setManagingOrganization(new Reference(org)); str = p.encodeResourceToString(patient); assertThat(str, StringContains.containsString("\"contained\":[{\"resourceType\":\"Organization\"")); }
@Test public void testEncodeContainedResourcesMore() { DiagnosticReport rpt = new DiagnosticReport(); Specimen spm = new Specimen(); rpt.getText().setDiv("AAA"); rpt.addSpecimen().setResource(spm); IParser p = new FhirContext(DiagnosticReport.class).newJsonParser().setPrettyPrint(true); String str = p.encodeResourceToString(rpt); ourLog.info(str); assertThat(str, StringContains.containsString("<div xmlns=\\\"http://www.w3.org/1999/xhtml\\\">AAA</div>")); String substring = "\"reference\": \"#"; assertThat(str, StringContains.containsString(substring)); int idx = str.indexOf(substring) + substring.length(); int idx2 = str.indexOf('"', idx + 1); String id = str.substring(idx, idx2); assertThat(str, StringContains.containsString("\"id\": \"" + id + "\"")); assertThat(str, IsNot.not(StringContains.containsString("<?xml version='1.0'?>"))); }
@Test public void testEncodeResourceRef() throws DataFormatException { Patient patient = new Patient(); patient.setManagingOrganization(new ResourceReferenceDt()); IParser p = ourCtx.newJsonParser(); String str = p.encodeResourceToString(patient); assertThat(str, IsNot.not(StringContains.containsString("managingOrganization"))); patient.setManagingOrganization(new ResourceReferenceDt("Organization/123")); str = p.encodeResourceToString(patient); assertThat(str, StringContains.containsString("\"managingOrganization\":{\"reference\":\"Organization/123\"}")); Organization org = new Organization(); org.addIdentifier().setSystem("foo").setValue("bar"); patient.setManagingOrganization(new ResourceReferenceDt(org)); str = p.encodeResourceToString(patient); assertThat(str, StringContains.containsString("\"contained\":[{\"resourceType\":\"Organization\"")); }
@Test public void testEncodeContainedResources() throws Exception { DiagnosticReport rpt = new DiagnosticReport(); Specimen spm = new Specimen(); spm.addIdentifier().setSystem("urn").setValue("123"); rpt.getText().setDivAsString("AAA"); rpt.addSpecimen().setResource(spm); IParser p = ourCtx.newXmlParser().setPrettyPrint(true); String str = p.encodeResourceToString(rpt); ourLog.info(str); assertThat(str, StringContains.containsString("<div xmlns=\"http://www.w3.org/1999/xhtml\">AAA</div>")); assertThat(str, StringContains.containsString("reference value=\"#")); int idx = str.indexOf("reference value=\"#") + "reference value=\"#".length(); int idx2 = str.indexOf('"', idx + 1); String id = str.substring(idx, idx2); assertThat(str, stringContainsInOrder("<Specimen xmlns=\"http://hl7.org/fhir\">", "<id value=\"" + id + "\"/>")); assertThat(str, IsNot.not(StringContains.containsString("<?xml version='1.0'?>"))); }
@Test public void testEncodeResourceRef() throws DataFormatException { Patient patient = new Patient(); patient.setManagingOrganization(new Reference()); IParser p = ourCtx.newXmlParser(); String str = p.encodeResourceToString(patient); assertThat(str, IsNot.not(StringContains.containsString("managingOrganization"))); Reference ref = new Reference(); ref.setReference("Organization/123"); ref.setDisplay("DISPLAY!"); patient.setManagingOrganization(ref); str = p.encodeResourceToString(patient); assertThat(str, StringContains.containsString( "<managingOrganization><reference value=\"Organization/123\"/><display value=\"DISPLAY!\"/></managingOrganization>")); Organization org = new Organization(); org.addIdentifier().setSystem("foo").setValue("bar"); patient.setManagingOrganization(new Reference(org)); str = p.encodeResourceToString(patient); assertThat(str, StringContains.containsString("<contained><Organization")); }
@Test public void testEncodeContainedResourcesMore() throws Exception { DiagnosticReport rpt = new DiagnosticReport(); Specimen spm = new Specimen(); rpt.getText().setDivAsString("AAA"); rpt.addSpecimen().setResource(spm); IParser p = ourCtx.newJsonParser().setPrettyPrint(true); String str = p.encodeResourceToString(rpt); ourLog.info(str); assertThat(str, StringContains.containsString("<div xmlns=\\\"http://www.w3.org/1999/xhtml\\\">AAA</div>")); String substring = "\"reference\": \"#"; assertThat(str, StringContains.containsString(substring)); int idx = str.indexOf(substring) + substring.length(); int idx2 = str.indexOf('"', idx + 1); String id = str.substring(idx, idx2); assertThat(str, StringContains.containsString("\"id\": \"" + id + "\"")); assertThat(str, IsNot.not(StringContains.containsString("<?xml version='1.0'?>"))); }
@Test public void testEncodeResourceRef() throws DataFormatException { Patient patient = new Patient(); patient.setManagingOrganization(new Reference()); IParser p = ourCtx.newJsonParser(); String str = p.encodeResourceToString(patient); assertThat(str, IsNot.not(StringContains.containsString("managingOrganization"))); patient.setManagingOrganization(new Reference("Organization/123")); str = p.encodeResourceToString(patient); assertThat(str, StringContains.containsString("\"managingOrganization\":{\"reference\":\"Organization/123\"}")); Organization org = new Organization(); org.addIdentifier().setSystem("foo").setValue("bar"); patient.setManagingOrganization(new Reference(org)); str = p.encodeResourceToString(patient); assertThat(str, StringContains.containsString("\"contained\":[{\"resourceType\":\"Organization\"")); }
/** * Test if content is added correctly if expectPartnerToken is set. * * @throws ServiceValidationException * @throws XMLStreamException the XML stream exception * @throws ServiceXmlSerializationException the service xml serialization exception */ @Test public void testWriteExtraCustomSoapHeadersToXmlWithPartnertoken() throws ServiceValidationException, XMLStreamException, ServiceXmlSerializationException { GetUserSettingsRequest getUserSettingsRequest = new GetUserSettingsRequest(autodiscoverService, uriMockHttps, Boolean.TRUE); // Test without expected Partnertoken ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); getUserSettingsRequest.writeExtraCustomSoapHeadersToXml( new EwsServiceXmlWriter(exchangeServiceBaseMock, byteArrayOutputStream)); // data should be added the same way as mentioned Assert.assertThat(byteArrayOutputStream.toByteArray(), IsNot.not(new ByteArrayOutputStream().toByteArray())); //TODO Test if the output is really correct }
/** * Test for checking if the value changes in case of a thrown exception * * @throws Exception */ @Test public void testDontChangeValueOnException() throws Exception { // set valid value final Double targetValue = 50.5; taskMock.setPercentComplete(targetValue); assertThat(taskMock.getPercentComplete(), IsNot.not(IsNull.nullValue())); assertThat(taskMock.getPercentComplete(), IsInstanceOf.instanceOf(Double.class)); assertThat(taskMock.getPercentComplete(), IsEqual.equalTo(targetValue)); final Double invalidValue = -0.1; try { taskMock.setPercentComplete(invalidValue); } catch (IllegalArgumentException ex) { // ignored } assertThat(taskMock.getPercentComplete(), IsNot.not(IsNull.nullValue())); assertThat(taskMock.getPercentComplete(), IsInstanceOf.instanceOf(Double.class)); assertThat(taskMock.getPercentComplete(), IsEqual.equalTo(targetValue)); }
@Test public void testQueryWithHighlight() { HighlightPage<ProductBean> page = repo.findByNameHighlightAll("na", new PageRequest(0, 10)); Assert.assertEquals(3, page.getNumberOfElements()); for (ProductBean product : page) { List<Highlight> highlights = page.getHighlights(product); Assert.assertThat(highlights, IsNot.not(IsEmptyCollection.empty())); for (Highlight highlight : highlights) { Assert.assertEquals("name", highlight.getField().getName()); Assert.assertThat(highlight.getSnipplets(), IsNot.not(IsEmptyCollection.empty())); for (String s : highlight.getSnipplets()) { Assert.assertTrue("expected to find <em>name</em> but was \"" + s + "\"", s.contains("<em>name</em>")); } } } }
@Test public void testHighlightWithPrefixPostfix() { HighlightPage<ProductBean> page = repo.findByNameHighlightAllWithPreAndPostfix("na", new PageRequest(0, 10)); Assert.assertEquals(3, page.getNumberOfElements()); for (ProductBean product : page) { List<Highlight> highlights = page.getHighlights(product); Assert.assertThat(highlights, IsNot.not(IsEmptyCollection.empty())); for (Highlight highlight : highlights) { Assert.assertEquals("name", highlight.getField().getName()); Assert.assertThat(highlight.getSnipplets(), IsNot.not(IsEmptyCollection.empty())); for (String s : highlight.getSnipplets()) { Assert.assertTrue("expected to find <b>name</b> but was \"" + s + "\"", s.contains("<b>name</b>")); } } } }
@Test public void testHighlightWithFields() { ProductBean beanWithText = createProductBean("withName", 5, true); beanWithText.setDescription("some text with name in it"); repo.save(beanWithText); HighlightPage<ProductBean> page = repo.findByNameHighlightAllLimitToFields("na", new PageRequest(0, 10)); Assert.assertEquals(4, page.getNumberOfElements()); for (ProductBean product : page) { List<Highlight> highlights = page.getHighlights(product); if (!product.getId().equals(beanWithText.getId())) { Assert.assertThat(highlights, IsEmptyCollection.empty()); } else { Assert.assertThat(highlights, IsNot.not(IsEmptyCollection.empty())); for (Highlight highlight : highlights) { Assert.assertEquals("description", highlight.getField().getName()); Assert.assertThat(highlight.getSnipplets(), IsNot.not(IsEmptyCollection.empty())); for (String s : highlight.getSnipplets()) { Assert.assertTrue("expected to find <em>name</em> but was \"" + s + "\"", s.contains("<em>name</em>")); } } } } }
@Test public void shouldNotScheduleWhenPipelineRemovedFromConfigRepoWhenManuallyTriggered() throws Exception { configTestRepo.addCodeToRepositoryAndPush(fileName, "removed pipeline from configuration", "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<cruise xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"cruise-config.xsd\" schemaVersion=\"38\">\n" + "</cruise>"); final HashMap<String, String> revisions = new HashMap<>(); final HashMap<String, String> environmentVariables = new HashMap<>(); buildCauseProducer.manualProduceBuildCauseAndSave(PIPELINE_NAME, Username.ANONYMOUS, new ScheduleOptions(revisions, environmentVariables, new HashMap<>()), new ServerHealthStateOperationResult()); waitForMaterialNotInProgress(); // config is correct cachedGoConfig.throwExceptionIfExists(); assertThat(pipelineScheduleQueue.toBeScheduled().keySet(), IsNot.not(hasItem(PIPELINE_NAME))); assertThat(goConfigService.hasPipelineNamed(pipelineConfig.name()),is(false)); }
@Test public void testSafeFileDeleteFile() throws Exception { UUID uuid = UUID.randomUUID(); Path fileUnderTest = Paths.get(ROOT_DIR, uuid.toString()); FileUtils.touch(fileUnderTest.toString(), 10 * FILE_SIZE_FACTOR); byte[] sha1SumBefore; try (FileInputStream fileInputStream = new FileInputStream(fileUnderTest.toFile())) { sha1SumBefore = DigestUtils.sha1(fileInputStream); } long fileLengthBefore = fileUnderTest.toFile().length(); RandomBytesNoiseGenerator noiseGenerator = new RandomBytesNoiseGenerator(); SafeDelete safeDelete = new SafeDelete(noiseGenerator); safeDelete.generateNoise(fileUnderTest); byte[] sha1SumAfter; try (FileInputStream fileInputStream = new FileInputStream(fileUnderTest.toFile())) { sha1SumAfter = DigestUtils.sha1(fileInputStream); } long fileLengthAfter = fileUnderTest.toFile().length(); Assert.assertThat(sha1SumBefore, IsNot.not(IsEqual.equalTo(sha1SumAfter))); Assert.assertEquals(fileLengthBefore, fileLengthAfter); }
@Test public void testSafeFileDeleteSmallFile() throws Exception { UUID uuid = UUID.randomUUID(); Path fileUnderTest = Paths.get(ROOT_DIR, uuid.toString()); FileUtils.touch(fileUnderTest.toString(), 10); byte[] sha1SumBefore; try (FileInputStream fileInputStream = new FileInputStream(fileUnderTest.toFile())) { sha1SumBefore = DigestUtils.sha1(fileInputStream); } long fileLengthBefore = fileUnderTest.toFile().length(); RandomBytesNoiseGenerator noiseGenerator = new RandomBytesNoiseGenerator(); SafeDelete safeDelete = new SafeDelete(noiseGenerator); safeDelete.generateNoise(fileUnderTest); byte[] sha1SumAfter; try (FileInputStream fileInputStream = new FileInputStream(fileUnderTest.toFile())) { sha1SumAfter = DigestUtils.sha1(fileInputStream); } long fileLengthAfter = fileUnderTest.toFile().length(); Assert.assertThat(sha1SumBefore, IsNot.not(IsEqual.equalTo(sha1SumAfter))); Assert.assertEquals(fileLengthBefore, fileLengthAfter); }
@Test public void testSetLogger() { PagerAdaptersLogging.setLogger(null); assertThat(PagerAdaptersLogging.getLogger(), is(IsNot.not(IsNull.nullValue()))); final Logger logger = new SimpleLogger(Log.DEBUG); PagerAdaptersLogging.setLogger(logger); assertThat(PagerAdaptersLogging.getLogger(), is(logger)); }
@Test public void delete() throws Exception { final List<User> users = User.generate(50, true); final List<User> fetched = mAlchemy.insert(users).fetch().list(); final List<User> deleted = new ArrayList<>(); for (final User user : fetched) { if (user.getId() % 2 == 0) { deleted.add(user); } } mAlchemy.delete(deleted).run(); final List<User> allUsers = mAlchemy.where(User.class).fetch().list(); Assert.assertThat(allUsers, IsNot.not(IterableContains.inAnyOrder(deleted))); }
@Test public void delete_by_where() throws Exception { final List<User> users = User.generate(50, true); mAlchemy.insert(users).run(); final List<User> deleted = new ArrayList<>(); for (final User user : deleted) { if (user.getAge() < 25) { deleted.add(user); } } mAlchemy.where(User.class).lessThan(UserContract.AGE, 25).delete().run(); final List<User> allUsers = mAlchemy.where(User.class).fetch().list(); Assert.assertThat(allUsers, IsNot.not(IterableContains.inAnyOrder(deleted))); }
@Test public void testSetLogger() { FragmentsLogging.setLogger(null); assertThat(FragmentsLogging.getLogger(), is(IsNot.not(IsNull.nullValue()))); final Logger logger = new SimpleLogger(Log.DEBUG); FragmentsLogging.setLogger(logger); assertThat(FragmentsLogging.getLogger(), is(logger)); }
@Ignore @Test public void fetchCodesFromRealSpreadsheet() throws Exception { final ProgressService service = JujacoreProgressServiceIntegrationTest .injector.getInstance(ProgressService.class); final Set<String> codes = service.codes(); MatcherAssert.assertThat( codes, IsCollectionWithSize.hasSize(251) ); MatcherAssert.assertThat(codes, IsNot.not( IsCollectionContaining.hasItem("")) ); }
@Test public void testPrimitiveClasses() { Portability<Serializable> p = new SerializablePortability(); Class[] out = (Class[]) p.decode(p.encode(PRIMITIVE_CLASSES)); Assert.assertThat(out, IsNot.not(IsSame.sameInstance(PRIMITIVE_CLASSES))); Assert.assertThat(out, IsEqual.equalTo(PRIMITIVE_CLASSES)); }
@Before public void setup() { mockService = new MockCallableHttpService(); endpoint = directory.getEndpoint(GreetingsService.class); assertThat(endpoint, is(IsNot.not(IsNull.nullValue()))); httpRequestExecutor = new HttpRequestExecutor(); }
@Test public void shouldCreateFileSystemAwareUiHttpContext() { HttpContext httpContext = mock(HttpContext.class); PowerMockito.mockStatic(ApplicationEnvironment.class); MockBundle bundle = new MockBundle("org.motechproject.com-sms-api-bundle"); when(ApplicationEnvironment.isInDevelopmentMode()).thenReturn(true); when(ApplicationEnvironment.getModulePath(new BundleName("org.motechproject.com-sms-api-bundle"))).thenReturn("/Users/s/project/motech/modules/sms/src/main/resources"); FileSystemAwareUIHttpContext fileSystemAwareUIHttpContext = (FileSystemAwareUIHttpContext) HttpContextFactory.getHttpContext(httpContext, bundle); assertThat(fileSystemAwareUIHttpContext, IsNot.not(notNull())); assertThat(fileSystemAwareUIHttpContext.getResourceRootDirectoryPath(), Is.is("/Users/s/project/motech/modules/sms/src/main/resources")); }
@Test public void testEncodeContainedResources() { DiagnosticReport rpt = new DiagnosticReport(); rpt.getText().setDiv("AAA"); Specimen spm = new Specimen(); spm.addIdentifier("urn", "123"); rpt.addSpecimen().setResource(spm); spm = new Specimen(); spm.addIdentifier("urn", "456"); rpt.addSpecimen().setResource(spm); IParser p = ourCtx.newXmlParser().setPrettyPrint(true); String str = p.encodeResourceToString(rpt); ourLog.info(str); //@formatter:off // Ensure that contained resources are encoded as children of separate <contained> elements // (As of 0.9, See #84) assertThat(str, stringContainsInOrder(Arrays.asList( "<contained>", "<Specimen", "</contained>", "<contained>", "<Specimen", "</contained>", "<specimen>", "<reference"))); //@formatter:on assertThat(str, StringContains.containsString("<div xmlns=\"http://www.w3.org/1999/xhtml\">AAA</div>")); assertThat(str, StringContains.containsString("reference value=\"#")); int idx = str.indexOf("reference value=\"#") + "reference value=\"#".length(); int idx2 = str.indexOf('"', idx + 1); String id = str.substring(idx, idx2); assertThat(str, StringContains.containsString("<Specimen xmlns=\"http://hl7.org/fhir\" id=\"" + id + "\">")); assertThat(str, IsNot.not(StringContains.containsString("<?xml version='1.0'?>"))); }
@Test public void testPrettyPrint() throws Exception { /* * Not specified */ HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/1"); HttpResponse status = ourClient.execute(httpGet); String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent()); assertThat(responseContent, StringContains.containsString("<identifier><use")); /* * Disabled */ httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/1?_pretty=false"); status = ourClient.execute(httpGet); responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent()); assertThat(responseContent, StringContains.containsString("<identifier><use")); /* * Enabled */ httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/1?_pretty=true"); status = ourClient.execute(httpGet); responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent()); assertThat(responseContent, IsNot.not(StringContains.containsString("<identifier><use"))); }
@Test public void testPrimitiveClasses() throws ClassNotFoundException { @SuppressWarnings("unchecked") StatefulSerializer<Serializable> s = new CompactJavaSerializer(null); s.init(new TransientStateRepository()); Class[] out = (Class[]) s.read(s.serialize(PRIMITIVE_CLASSES)); Assert.assertThat(out, IsNot.not(IsSame.sameInstance(PRIMITIVE_CLASSES))); Assert.assertThat(out, IsEqual.equalTo(PRIMITIVE_CLASSES)); }
@Test public void jsonDataEncrypted() throws IOException, QueryException { File jsonDatabase = new File(datastoreManagerDir + File.separator + "EndToEndEncryptionTest" + File.separator + "db.sync"); // Database creation happens in the background, so we need to call a blocking // database operation to ensure the database exists on disk before we look at // it. Query im = this.database.query(); try { im.createJsonIndex(Arrays.<FieldSort>asList(new FieldSort("name"), new FieldSort("age")), null); } finally { ((QueryImpl)im).close(); } InputStream in = new FileInputStream(jsonDatabase); byte[] magicBytesBuffer = new byte[sqlCipherMagicBytes.length]; int readLength = in.read(magicBytesBuffer); assertEquals("Didn't read full buffer", magicBytesBuffer.length, readLength); if (dataShouldBeEncrypted) { assertThat("SQLite magic bytes found in file that should be encrypted", sqlCipherMagicBytes, IsNot.not(IsEqual.equalTo(magicBytesBuffer))); } else { assertThat("SQLite magic bytes not found in file that should not be encrypted", sqlCipherMagicBytes, IsEqual.equalTo(magicBytesBuffer)); } }
@Test public void indexDataEncrypted() throws IOException, QueryException { Query im = this.database.query(); try { im.createJsonIndex(Arrays.<FieldSort>asList(new FieldSort("name"), new FieldSort("age")), null); } finally { ((QueryImpl)im).close(); } File jsonDatabase = new File(datastoreManagerDir + File.separator + "EndToEndEncryptionTest" + File.separator + "extensions" + File.separator + "com.cloudant.sync.query" + File.separator + "indexes.sqlite"); InputStream in = new FileInputStream(jsonDatabase); byte[] magicBytesBuffer = new byte[sqlCipherMagicBytes.length]; int readLength = in.read(magicBytesBuffer); assertEquals("Didn't read full buffer", magicBytesBuffer.length, readLength); if (dataShouldBeEncrypted) { assertThat("SQLite magic bytes found in file that should be encrypted", sqlCipherMagicBytes, IsNot.not(IsEqual.equalTo(magicBytesBuffer))); } else { assertThat("SQLite magic bytes not found in file that should not be encrypted", sqlCipherMagicBytes, IsEqual.equalTo(magicBytesBuffer)); } }
/** * Test for adding 0.0 as percentCompleted * * @throws Exception */ @Test public void testAddZeroPercent() throws Exception { final Double targetValue = 0.0; taskMock.setPercentComplete(targetValue); assertThat(taskMock.getPercentComplete(), IsNot.not(IsNull.nullValue())); assertThat(taskMock.getPercentComplete(), IsInstanceOf.instanceOf(Double.class)); assertThat(taskMock.getPercentComplete(), IsEqual.equalTo(targetValue)); }
/** * Test for adding 100.0 as percentCompleted * * @throws Exception */ @Test public void testAdd100Percent() throws Exception { final Double targetValue = 100.0; taskMock.setPercentComplete(targetValue); assertThat(taskMock.getPercentComplete(), IsNot.not(IsNull.nullValue())); assertThat(taskMock.getPercentComplete(), IsInstanceOf.instanceOf(Double.class)); assertThat(taskMock.getPercentComplete(), IsEqual.equalTo(targetValue)); }
@Test public void runCodeSimple() throws Exception { ResultActions actions = this.mockMvc.perform(post("/jhawtcode/dynacode").param("code", "jhc.println(true);").param("replacementCP", fullClassPath)); //actions.andDo(print()); actions.andExpect(status().isOk()); //not the best content test, but works for now until gzip deflate actions.andExpect(content().string(new IsNot(new IsNull()))); actions.andExpect(content().string(new IsNot(new IsEmptyString()))); actions.andExpect(content().string(new IsEqualIgnoringWhiteSpace("true"))); }