@Test public void standard() throws Exception { CryptoAssumptions.assumeCBCJCE(); BytesEncryptor encryptor = Encryptors.standard("password", "5c0744940b5c369b"); byte[] result = encryptor.encrypt("text".getBytes("UTF-8")); assertThat(result).isNotNull(); assertThat(new String(result).equals("text")).isFalse(); assertThat(new String(encryptor.decrypt(result))).isEqualTo("text"); assertThat(new String(result)).isNotEqualTo( new String(encryptor.encrypt("text".getBytes()))); }
@Test public void stronger() throws Exception { CryptoAssumptions.assumeGCMJCE(); BytesEncryptor encryptor = Encryptors.stronger("password", "5c0744940b5c369b"); byte[] result = encryptor.encrypt("text".getBytes("UTF-8")); assertThat(result).isNotNull(); assertThat(new String(result).equals("text")).isFalse(); assertThat(new String(encryptor.decrypt(result))).isEqualTo("text"); assertThat(new String(result)).isNotEqualTo( new String(encryptor.encrypt("text".getBytes()))); }
@Test public void testToByteArray() throws IOException { final byte[] expected = new byte[] {(byte) 0xCA, (byte) 0xFE, (byte) 0xBA, (byte) 0xBE}; final byte[] actual = IOUtils.toByteArray(new ByteArrayInputStream(expected)); assertThat(actual).isNotNull(); assertThat(actual.length).isEqualTo(expected.length); assertThat(actual).isEqualTo(expected); }
@Test public void testObjectSerializationWithClassLoader() throws IOException, ClassNotFoundException { final BigDecimal pi = new BigDecimal(Math.PI); final byte[] piBytes = IOUtils.serializeObject(pi); assertThat(piBytes).isNotNull(); assertThat(piBytes.length != 0).isTrue(); final Object piObj = IOUtils.deserializeObject(piBytes, IOUtilsJUnitTest.class.getClassLoader()); assertThat(piObj).isInstanceOf(BigDecimal.class); assertThat(piObj).isEqualTo(pi); }
@Test public void testObjectSerialization() throws IOException, ClassNotFoundException { final Calendar now = Calendar.getInstance(); assertThat(now).isNotNull(); final byte[] nowBytes = IOUtils.serializeObject(now); assertThat(nowBytes).isNotNull(); assertThat(nowBytes.length != 0).isTrue(); final Object nowObj = IOUtils.deserializeObject(nowBytes); assertThat(nowObj).isInstanceOf(Calendar.class); assertThat(((Calendar) nowObj).getTimeInMillis()).isEqualTo(now.getTimeInMillis()); }
@Test public void serializeToBlobMapReturnsBytesOfMap() throws Exception { byte[] bytes = serializeToBlob(this.mapWithTwoEntries); assertThat(bytes).isNotNull().isEqualTo(this.bytesOfMap); }
@Test public void testWithKeySelector() { final KafkaStructuredLoggingServiceExposed service = new KafkaStructuredLoggingServiceExposed( producer, (res, log) -> log.name.getBytes(), false); final SimpleStructuredLog log = new SimpleStructuredLog("kawamuray"); service.writeLog(null, log); verify(producer, times(1)).send(captor.capture(), any(Callback.class)); final ProducerRecord<byte[], SimpleStructuredLog> record = captor.getValue(); assertThat(record.key()).isNotNull(); assertThat(new String(record.key())).isEqualTo(log.name); assertThat(record.value()).isEqualTo(log); }
@Test void downloadStarter() { byte[] body = getRestTemplate().getForObject(createUrl("starter.zip"), byte[].class); assertThat(body).isNotNull(); assertThat(body.length).isGreaterThan(100); }
@Test public void serializeToBlobWithNullReturnsBytesOfNull() throws Exception { byte[] bytes = serializeToBlob(null); assertThat(bytes).isNotNull().isEqualTo(this.bytesOfNull); }
@Test public void constructorWhenCreatedThenIsSerializableAndDeserializable() { OAuth2AccessToken accessToken = new OAuth2AccessToken( TOKEN_TYPE, TOKEN_VALUE, ISSUED_AT, EXPIRES_AT, SCOPES); byte[] serialized = SerializationUtils.serialize(accessToken); accessToken = (OAuth2AccessToken) SerializationUtils.deserialize(serialized); assertThat(serialized).isNotNull(); assertThat(accessToken.getTokenType()).isEqualTo(TOKEN_TYPE); assertThat(accessToken.getTokenValue()).isEqualTo(TOKEN_VALUE); assertThat(accessToken.getIssuedAt()).isEqualTo(ISSUED_AT); assertThat(accessToken.getExpiresAt()).isEqualTo(EXPIRES_AT); assertThat(accessToken.getScopes()).isEqualTo(SCOPES); } }
@Test public void serializeMapToStreamWritesMapAsBytes() throws Exception { HeapDataOutputStream hdos = createHeapDataOutputStream(); serializeTo(this.mapWithTwoEntries, hdos); assertThat(hdos.toByteArray()).isNotNull().isEqualTo(bytesOfMap); }
@Test public void serializeNullToStreamWritesNullAsBytes() throws Exception { HeapDataOutputStream hdos = createHeapDataOutputStream(); serializeTo(null, hdos); assertThat(hdos.toByteArray()).isNotNull().isEqualTo(this.bytesOfNull); }
@Test public void dataSerializes() throws Exception { EvictionAttributesImpl evictionAttributes = new EvictionAttributesImpl(); byte[] bytes = BlobHelper.serializeToBlob(evictionAttributes); assertThat(bytes).isNotNull().isNotEmpty(); assertThat(BlobHelper.deserializeBlob(bytes)).isNotSameAs(evictionAttributes) .isInstanceOf(EvictionAttributesImpl.class); }
@Test public void dataSerializes() throws Exception { PartitionRegionConfig config = new PartitionRegionConfig(prId, path, partitionAttributes, scope, evictionAttributes, regionIdleTimeout, regionTimeToLive, entryIdleTimeout, entryTimeToLive, gatewaySenderIds); byte[] bytes = BlobHelper.serializeToBlob(config); assertThat(bytes).isNotNull().isNotEmpty(); assertThat(BlobHelper.deserializeBlob(bytes)).isNotSameAs(config) .isInstanceOf(PartitionRegionConfig.class); }
@Test public void serializes() throws Exception { EvictionAttributesImpl evictionAttributes = new EvictionAttributesImpl(); byte[] bytes = SerializationUtils.serialize(evictionAttributes); assertThat(bytes).isNotNull().isNotEmpty(); assertThat((EvictionAttributesImpl) SerializationUtils.deserialize(bytes)) .isNotSameAs(evictionAttributes) .isInstanceOf(EvictionAttributesImpl.class); } }
@Ignore("GEODE-4812") @Test public void serializes() throws Exception { PartitionRegionConfig config = new PartitionRegionConfig(); byte[] bytes = SerializationUtils.serialize(config); assertThat(bytes).isNotNull().isNotEmpty(); assertThat((PartitionRegionConfig) SerializationUtils.deserialize(bytes)).isNotSameAs(config) .isInstanceOf(PartitionRegionConfig.class); } }
@Test public void testReserializedNonTrusted() { DefaultKafkaHeaderMapper mapper = new DefaultKafkaHeaderMapper(); Message<String> message = MessageBuilder.withPayload("foo") .setHeader("fix", new Foo()) .build(); RecordHeaders recordHeaders = new RecordHeaders(); mapper.fromHeaders(message.getHeaders(), recordHeaders); assertThat(recordHeaders.toArray().length).isEqualTo(2); // 1 + json_types Map<String, Object> headers = new HashMap<>(); mapper.toHeaders(recordHeaders, headers); assertThat(headers.get("fix")).isInstanceOf(NonTrustedHeaderType.class); NonTrustedHeaderType ntht = (NonTrustedHeaderType) headers.get("fix"); assertThat(ntht.getHeaderValue()).isNotNull(); assertThat(ntht.getUntrustedType()).isEqualTo(Foo.class.getName()); assertThat(headers).hasSize(1); recordHeaders = new RecordHeaders(); mapper.fromHeaders(new MessageHeaders(headers), recordHeaders); headers = new HashMap<>(); mapper.toHeaders(recordHeaders, headers); assertThat(headers.get("fix")).isInstanceOf(NonTrustedHeaderType.class); ntht = (NonTrustedHeaderType) headers.get("fix"); assertThat(ntht.getHeaderValue()).isNotNull(); assertThat(ntht.getUntrustedType()).isEqualTo(Foo.class.getName()); mapper.addTrustedPackages(getClass().getPackage().getName()); headers = new HashMap<>(); mapper.toHeaders(recordHeaders, headers); assertThat(headers.get("fix")).isInstanceOf(Foo.class); }
assertThat(headers.get("customToString")).isEqualTo("Bar [field=fiz]"); NonTrustedHeaderType ntht = (NonTrustedHeaderType) headers.get("fix"); assertThat(ntht.getHeaderValue()).isNotNull(); assertThat(ntht.getUntrustedType()).isEqualTo(Foo.class.getName()); assertThat(headers).hasSize(8);
protected void testRandomLengthInMemory(DiskBackedByteStore byteStore, int length) throws IOException { byte[] buffer = createRandomFilledBuffer(length); byteStore.write(buffer); assertThat(byteStore.swapped()).isFalse(); assertThat(byteStore.getData()).isNotNull().isEqualTo(buffer); }
@Test public void parseBytesOrNullTestForEmpty() throws Exception { // Do byte[] bytes = BeaconContentUtil.parseBytesOrNull(""); // Verify assertThat(bytes).isNotNull().isEmpty(); }