Java Code Examples for org.unitils.reflectionassert.ReflectionAssert

The following examples show how to use org.unitils.reflectionassert.ReflectionAssert. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: easybundler   Source File: EasyBundlerTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testPrivateFieldsNoGetter() {
    PrivateFieldsNoGetterObject obj1 = new PrivateFieldsNoGetterObject();
    obj1.publicString = "Hello";
    obj1.setPrivateInt(456);

    PrivateFieldsNoGetterObject obj2 = bundleAndUnbundle(obj1);

    // Public field should be bundled properly
    assertEquals(obj1.publicString, obj2.publicString);

    // Private field without getter should have been ignored
    try {
        ReflectionAssert.assertReflectionEquals(obj1, obj2);
        throw new RuntimeException("Should not have gotten here!");
    } catch (AssertionFailedError e) {
        // We expect to get to this branch.
    }
}
 
Example 2
@Test
public void test_zone_extracted_list_of_servers() throws MarathonException {
    ReflectionAssert.assertReflectionEquals(
            "should be two servers",
            IntStream.of(1,2)
                    .mapToObj(index ->
                            new MarathonServer(
                                    "host" + index + ".dc1",
                                    9090,
                                    Collections.emptyList())
                            .withZone("dc1")
                    ).collect(Collectors.toList()),
            serverList.getInitialListOfServers().stream()
                .filter(server -> server.getZone().equals("dc1"))
                .collect(Collectors.toList()),
            ReflectionComparatorMode.LENIENT_ORDER
    );
}
 
Example 3
Source Project: twill   Source File: ResourceSpecificationCodecTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testCodec() throws Exception {
  String expectedString =
          "{" +
                  "\"cores\":2," +
                  "\"memorySize\":1024," +
                  "\"instances\":2," +
                  "\"uplink\":100," +
                  "\"downlink\":100" +
          "}";
  final ResourceSpecification expected =
          new DefaultResourceSpecification(2, 1024, 2, 100, 100);
  final String actualString = gson.toJson(expected);
  Assert.assertEquals(expectedString, actualString);

  final JsonElement expectedJson = gson.toJsonTree(expected);
  final ResourceSpecification actual = gson.fromJson(expectedJson, DefaultResourceSpecification.class);
  final JsonElement actualJson = gson.toJsonTree(actual);

  Assert.assertEquals(expectedJson, actualJson);
  ReflectionAssert.assertLenientEquals(expected, actual);
}
 
Example 4
Source Project: rest-example   Source File: RestResourceTestBase.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Tests retrieving one entity.
 * An entity should be retrieved and the properties of the entity should have the
 * same values as the entity persisted before the test.
 *
 * @throws IOException If error occurs. Indicates test failure.
 */
@Test(timeOut = TEST_TIMEOUT)
public void testGetEntity() throws IOException {
    final Response theResponse = RestAssured
        .given()
        .contentType("application/json")
        .accept("application/json")
        .when()
        .get(mResourceUrlPath + "/" + mExpectedEntity.getId());
    final String theResponseJson = theResponse.prettyPrint();
    theResponse
        .then()
        .statusCode(200)
        .contentType(ContentType.JSON);

    final Object theRetrievedEntity = JsonConverter.jsonToObject(
        theResponseJson, mExpectedEntity.getClass());
    ReflectionAssert.assertLenientEquals(
        "Retrieved entity should have the correct property values",
        mExpectedEntity, theRetrievedEntity);
}
 
Example 5
Source Project: kripton   Source File: AbstractBindTypeProcessorTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Serialize and parse collection binary.
 *
 * @param <E> the element type
 * @param list the list
 * @param clazz the clazz
 * @param type the type
 * @return the int
 * @throws Exception the exception
 */
public <E> int serializeAndParseCollectionBinary(Collection<E> list, Class<E> clazz, BinderType type) throws Exception {
	KriptonByteArrayOutputStream bar = new KriptonByteArrayOutputStream();
	KriptonBinder.bind(type).serializeCollection(list, clazz, bar);
	String value1 = toString(bar.getByteBuffer());

	Collection<E> list2 = KriptonBinder.bind(type).parseCollection(bar.getByteBufferCopy(), new ArrayList<E>(), clazz);

	KriptonByteArrayOutputStream bar2 = new KriptonByteArrayOutputStream();
	KriptonBinder.bind(type).serializeCollection(list2, clazz, bar2);
	String value2 = toString(bar2.getByteBuffer());

	System.out.println(value1);
	System.out.println(value2);

	Assert.assertTrue(value1.length() == value2.length());
	ReflectionAssert.assertReflectionEquals(type.toString(), list, list2, ReflectionComparatorMode.LENIENT_ORDER);
	//
	return bar.getCount();
}
 
Example 6
Source Project: kripton   Source File: AbstractBaseTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Serialize and parse.
 *
 * @param bean the bean
 * @param type the type
 * @return serialize and parse
 * @throws Exception the exception
 */
public int serializeAndParse(Object bean, BinderType type) throws Exception {
	String output1 = KriptonBinder.bind(type).serialize(bean);
	System.out.println("[[" + output1 + "]]");

	Object bean2 = KriptonBinder.bind(type).parse(output1, bean.getClass());

	String output2 = KriptonBinder.bind(type).serialize(bean2);
	if (output1.equals(output2)) {
		System.out.println("[[-- same --]]");
	} else {
		System.out.println("[[" + output2 + "]]");
	}

	Assert.assertTrue(type.toString(), output1.length() == output2.length());

	ReflectionAssert.assertReflectionEquals(bean, bean2, ReflectionComparatorMode.LENIENT_ORDER);

	return output2.length();
}
 
Example 7
Source Project: kripton   Source File: AbstractBaseTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Serialize and parse collection.
 *
 * @param <E> the element type
 * @param list the list
 * @param clazz the clazz
 * @param type the type
 * @return int
 * @throws Exception the exception
 */
public <E> int serializeAndParseCollection(Collection<E> list, Class<E> clazz, BinderType type) throws Exception {
	String value1 = KriptonBinder.bind(type).serializeCollection(list, clazz);

	System.out.println("[[" + value1 + "]]");

	Collection<E> list2 = KriptonBinder.bind(type).parseCollection(value1, new ArrayList<E>(), clazz);

	String value2 = KriptonBinder.bind(type).serializeCollection(list2, clazz);

	if (value1.equals(value2)) {
		System.out.println("[[-- same --]]");
	} else {
		System.out.println("[[" + value2 + "]]");
	}
	//
	Assert.assertTrue(value1.length() == value2.length());
	ReflectionAssert.assertReflectionEquals(type.toString(), list, list2, ReflectionComparatorMode.LENIENT_ORDER);
	//
	return value1.length();
}
 
Example 8
Source Project: kripton   Source File: AbstractBaseTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Serialize and parse collection binary.
 *
 * @param <E> the element type
 * @param list the list
 * @param clazz the clazz
 * @param type the type
 * @return int
 * @throws Exception the exception
 */
public <E> int serializeAndParseCollectionBinary(Collection<E> list, Class<E> clazz, BinderType type) throws Exception {
	KriptonByteArrayOutputStream bar = new KriptonByteArrayOutputStream();
	KriptonBinder.bind(type).serializeCollection(list, clazz, bar);
	String value1 = toString(bar.getByteBuffer());

	System.out.println("[[" + value1 + "]]");

	Collection<E> list2 = KriptonBinder.bind(type).parseCollection(bar.getByteBufferCopy(), new ArrayList<E>(), clazz);

	KriptonByteArrayOutputStream bar2 = new KriptonByteArrayOutputStream();
	KriptonBinder.bind(type).serializeCollection(list2, clazz, bar2);
	String value2 = toString(bar2.getByteBuffer());

	if (value1.equals(value2)) {
		System.out.println("[[-- same --]]");
	} else {
		System.out.println("[[" + value2 + "]]");
	}

	Assert.assertTrue(value1.length() == value2.length());
	ReflectionAssert.assertReflectionEquals(type.toString(), list, list2, ReflectionComparatorMode.LENIENT_ORDER);
	//
	return bar.getCount();
}
 
Example 9
Source Project: kripton   Source File: AbstractBaseTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Serialize and parse.
 *
 * @param bean the bean
 * @param type the type
 * @return the int
 * @throws Exception the exception
 */
public int serializeAndParse(Object bean, BinderType type) throws Exception {
	String output1 = KriptonBinder.bind(type).serialize(bean);
	System.out.println("[[" + output1 + "]]");

	Object bean2 = KriptonBinder.bind(type).parse(output1, bean.getClass());

	String output2 = KriptonBinder.bind(type).serialize(bean2);
	if (output1.equals(output2)) {
		System.out.println("[[-- same --]]");
	} else {
		System.out.println("[[" + output2 + "]]");
	}

	Assert.assertTrue(type.toString(), output1.length() == output2.length());

	ReflectionAssert.assertReflectionEquals(bean, bean2, ReflectionComparatorMode.LENIENT_ORDER);

	return output2.length();
}
 
Example 10
Source Project: kripton   Source File: AbstractBaseTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Serialize and parse collection.
 *
 * @param <E> the element type
 * @param list the list
 * @param clazz the clazz
 * @param type the type
 * @return the int
 * @throws Exception the exception
 */
public <E> int serializeAndParseCollection(Collection<E> list, Class<E> clazz, BinderType type) throws Exception {
	String value1 = KriptonBinder.bind(type).serializeCollection(list, clazz);

	System.out.println("[[" + value1 + "]]");

	Collection<E> list2 = KriptonBinder.bind(type).parseCollection(value1, new ArrayList<E>(), clazz);

	String value2 = KriptonBinder.bind(type).serializeCollection(list2, clazz);

	if (value1.equals(value2)) {
		System.out.println("[[-- same --]]");
	} else {
		System.out.println("[[" + value2 + "]]");
	}
	//
	Assert.assertTrue(value1.length() == value2.length());
	ReflectionAssert.assertReflectionEquals(type.toString(), list, list2, ReflectionComparatorMode.LENIENT_ORDER);
	//
	return value1.length();
}
 
Example 11
Source Project: kripton   Source File: AbstractBaseTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Serialize and parse collection binary.
 *
 * @param <E> the element type
 * @param list the list
 * @param clazz the clazz
 * @param type the type
 * @return the int
 * @throws Exception the exception
 */
public <E> int serializeAndParseCollectionBinary(Collection<E> list, Class<E> clazz, BinderType type) throws Exception {
	KriptonByteArrayOutputStream bar = new KriptonByteArrayOutputStream();
	KriptonBinder.bind(type).serializeCollection(list, clazz, bar);
	String value1 = toString(bar.getByteBuffer());

	System.out.println("[[" + value1 + "]]");

	Collection<E> list2 = KriptonBinder.bind(type).parseCollection(bar.getByteBufferCopy(), new ArrayList<E>(), clazz);

	KriptonByteArrayOutputStream bar2 = new KriptonByteArrayOutputStream();
	KriptonBinder.bind(type).serializeCollection(list2, clazz, bar2);
	String value2 = toString(bar2.getByteBuffer());

	if (value1.equals(value2)) {
		System.out.println("[[-- same --]]");
	} else {
		System.out.println("[[" + value2 + "]]");
	}

	Assert.assertTrue(value1.length() == value2.length());
	ReflectionAssert.assertReflectionEquals(type.toString(), list, list2, ReflectionComparatorMode.LENIENT_ORDER);
	//
	return bar.getCount();
}
 
Example 12
Source Project: easybundler   Source File: EasyBundlerTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Put an object into a Bundle and then extract it out again, use reflection to ensure that
 * the resulting object is the same.
 */
private <T> void checkSurvivesBundle(T obj1) {
    // Bundle to object
    T obj2 = bundleAndUnbundle(obj1);

    // Make sure the objects are deep equal
    ReflectionAssert.assertReflectionEquals(obj1, obj2);
}
 
Example 13
Source Project: spring-cloud-marathon   Source File: MarathonServerListTests.java    License: MIT License 5 votes vote down vote up
@Test
public void test_initial_list_of_servers() throws MarathonException {
    ReflectionAssert.assertReflectionEquals(
            "should be three servers",
            IntStream.of(1,2,3)
                    .mapToObj(index ->
                            new MarathonServer(
                                    "host" + index,
                                    9090,
                                    Collections.emptyList())
                    ).collect(Collectors.toList()),
            serverList.getInitialListOfServers(),
            ReflectionComparatorMode.LENIENT_ORDER
    );
}
 
Example 14
Source Project: spring-cloud-marathon   Source File: MarathonServerListTests.java    License: MIT License 5 votes vote down vote up
@Test
public void test_updated_list_of_servers() throws MarathonException {
    ReflectionAssert.assertReflectionEquals(
            "should be three servers",
            IntStream.of(1,2,3)
                    .mapToObj(index ->
                            new MarathonServer(
                                    "host" + index,
                                    9090,
                                    Collections.emptyList())
                    ).collect(Collectors.toList()),
            serverList.getUpdatedListOfServers(),
            ReflectionComparatorMode.LENIENT_ORDER
    );
}
 
Example 15
@Test
public void test_initial_list_of_servers() throws MarathonException {
    ReflectionAssert.assertReflectionEquals(
            "should be three servers",
            IntStream.of(1,2,3)
                    .mapToObj(index ->
                            new MarathonServer(
                                    "host" + index,
                                    9090,
                                    Collections.emptyList())
                    ).collect(Collectors.toList()),
            serverList.getInitialListOfServers(),
            ReflectionComparatorMode.LENIENT_ORDER
    );
}
 
Example 16
@Test
public void test_updated_list_of_servers() throws MarathonException {
    ReflectionAssert.assertReflectionEquals(
            "should be three servers",
            IntStream.of(1,2,3)
                    .mapToObj(index ->
                            new MarathonServer(
                                    "host" + index,
                                    9090,
                                    Collections.emptyList())
                    ).collect(Collectors.toList()),
            serverList.getUpdatedListOfServers(),
            ReflectionComparatorMode.LENIENT_ORDER
    );
}
 
Example 17
@Test
public void test_initial_list_of_servers() throws MarathonException {
    ReflectionAssert.assertReflectionEquals(
            "should be three servers",
            IntStream.of(1,2,3)
                    .mapToObj(index ->
                            new MarathonServer(
                                    "host" + index,
                                    9090,
                                    Collections.emptyList())
                    ).collect(Collectors.toList()),
            serverList.getInitialListOfServers(),
            ReflectionComparatorMode.LENIENT_ORDER
    );
}
 
Example 18
@Test
public void test_updated_list_of_servers() throws MarathonException {
    ReflectionAssert.assertReflectionEquals(
            "should be three servers",
            IntStream.of(1,2,3)
                    .mapToObj(index ->
                            new MarathonServer(
                                    "host" + index,
                                    9090,
                                    Collections.emptyList())
                    ).collect(Collectors.toList()),
            serverList.getUpdatedListOfServers(),
            ReflectionComparatorMode.LENIENT_ORDER
    );
}
 
Example 19
Source Project: twill   Source File: ResourceSpecificationCodecTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testBuilder() throws Exception {
  final ResourceSpecification actual = ResourceSpecification.Builder.with()
          .setVirtualCores(5)
          .setMemory(4, ResourceSpecification.SizeUnit.GIGA)
          .setInstances(3)
          .setUplink(10, ResourceSpecification.SizeUnit.GIGA)
          .setDownlink(5, ResourceSpecification.SizeUnit.GIGA)
          .build();
  final DefaultResourceSpecification expected =
          new DefaultResourceSpecification(5, 4096, 3, 10240, 5120);
  ReflectionAssert.assertLenientEquals(expected, actual);
}
 
Example 20
Source Project: twill   Source File: ResourceSpecificationCodecTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testBuilderWithLists() throws Exception {
  final ResourceSpecification actual = ResourceSpecification.Builder.with()
          .setVirtualCores(5)
          .setMemory(4, ResourceSpecification.SizeUnit.GIGA)
          .setInstances(3)
          .setUplink(10, ResourceSpecification.SizeUnit.GIGA)
          .setDownlink(5, ResourceSpecification.SizeUnit.GIGA)
          .build();
  final DefaultResourceSpecification expected =
          new DefaultResourceSpecification(5, 4096, 3, 10240, 5120);
  ReflectionAssert.assertLenientEquals(expected, actual);
}
 
Example 21
Source Project: rest-example   Source File: RestResourceTestBase.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Tests creation of one entity.
 * An entity should be created and the properties of the entity should have the
 * same values as the properties in the entity representation sent to
 * the service.
 *
 * @throws Exception If error occurs. Indicates test failure.
 */
@Test(timeOut = TEST_TIMEOUT)
public void testCreateEntity() throws Exception {
    mEntityRepository.deleteAll();
    final E theExpectedEntity = mEntityFactory.createEntity(1);
    final String theJsonRepresentation =
        JsonConverter.objectToJson(theExpectedEntity);

    final Response theResponse = RestAssured
        .given()
        .contentType("application/json")
        .accept("application/json")
        .body(theJsonRepresentation)
        .when()
        .post(mResourceUrlPath);
    final String theCreatedEntityJson = theResponse.prettyPrint();
    theResponse
        .then()
        .statusCode(200)
        .contentType(ContentType.JSON);

    final LongIdEntity theCreatedEntity =
        JsonConverter.jsonToObject(
            theCreatedEntityJson, theExpectedEntity.getClass());
    /*
     * Id will be null in new entity, need to set id so comparision
     * do not fail due to this.
     */
    theExpectedEntity.setId(theCreatedEntity.getId());
    ReflectionAssert.assertLenientEquals(
        "Created entity should have the correct property values",
        theExpectedEntity, theCreatedEntity);
}
 
Example 22
Source Project: rest-example   Source File: RestResourceTestBase.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Tests updating one entity.
 * An updated entity should be returned.
 *
 * @throws Exception If error occurs. Indicates test failure.
 */
@Test(timeOut = TEST_TIMEOUT)
public void testUpdateEntity() throws Exception {
    final Long theExistingEntityId = mExpectedEntity.getId();
    final E theExpectedEntity =
        mEntityFactory.createEntity(mCreateEntityIndex + 1);
    theExpectedEntity.setId(theExistingEntityId);
    final String theJsonRepresentation =
        JsonConverter.objectToJson(theExpectedEntity);
    final Response theResponse = RestAssured
        .given()
        .contentType("application/json")
        .accept("application/json")
        .body(theJsonRepresentation)
        .when()
        .put(mResourceUrlPath + "/" + mExpectedEntity.getId());
    final String theResponseJson = theResponse.prettyPrint();
    theResponse
        .then()
        .statusCode(200)
        .contentType(ContentType.JSON);

    final Object theUpdatedEntity = JsonConverter.jsonToObject(
        theResponseJson, mExpectedEntity.getClass());
    ReflectionAssert.assertLenientEquals(
        "Updated entity should have the correct property values",
        theExpectedEntity, theUpdatedEntity);
}
 
Example 23
Source Project: kripton   Source File: BaseProcessorTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Test each elements of two collections. It does not matter the
 * collections' kind. Elements are compared by reflection.
 *
 * @param collection1
 *            the collection 1
 * @param collection2
 *            the collection 2
 */
public void checkCollectionExactly(Collection<?> collection1, Collection<?> collection2) {
	assertEquals("collections does not have same size", collection1.size(), collection2.size());

	Iterator<?> i1 = collection1.iterator();
	Iterator<?> i2 = collection2.iterator();

	while (i1.hasNext()) {
		ReflectionAssert.assertReflectionEquals(i2.next(), i1.next(), ReflectionComparatorMode.LENIENT_ORDER);
	}
}
 
Example 24
Source Project: kripton   Source File: AbstractBindTypeProcessorTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Serialize and parse collection.
 *
 * @param <E> the element type
 * @param list the list
 * @param clazz the clazz
 * @param type the type
 * @return the int
 * @throws Exception the exception
 */
public <E> int serializeAndParseCollection(Collection<E> list, Class<E> clazz, BinderType type) throws Exception {
	String value1 = KriptonBinder.bind(type).serializeCollection(list, clazz);
	Collection<E> list2 = KriptonBinder.bind(type).parseCollection(value1, new ArrayList<E>(), clazz);

	String value2 = KriptonBinder.bind(type).serializeCollection(list2, clazz);

	System.out.println(value1);
	System.out.println(value2);
	//
	Assert.assertTrue(value1.length() == value2.length());
	ReflectionAssert.assertReflectionEquals(type.toString(), list, list2, ReflectionComparatorMode.LENIENT_ORDER);
	//
	return value1.length();
}
 
Example 25
Source Project: kripton   Source File: Test45Runtime.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Test app run.
 */
@Test
public void testAppRun()
{
	AppPreferences bean=createBean();		
	BindAppPreferences prefs = BindAppPreferences.getInstance();		
	prefs.write(bean);
	
	AppPreferences bean2=prefs.read();				
	ReflectionAssert.assertReflectionEquals(bean, bean2, ReflectionComparatorMode.LENIENT_ORDER);				
}
 
Example 26
Source Project: kripton   Source File: Test45Runtime.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Test app run fail.
 */
@Test(expected=AssertionFailedError.class)
public void testAppRunFail()
{
	AppPreferences bean=createBean();		
	BindAppPreferences prefs = BindAppPreferences.getInstance();		
	prefs.write(bean);
	
	bean.description="fail";
	
	AppPreferences bean2=prefs.read();				
	ReflectionAssert.assertReflectionEquals(bean, bean2, ReflectionComparatorMode.LENIENT_ORDER);			
}
 
Example 27
private void checkSerializer(Session session) throws Exception {
    SessionSerializer s = new SessionSerializer();
    ByteBuffer valueBuffer = s.serialize(session);

    Session session2 = s.deserialize(valueBuffer, 0, valueBuffer.limit());
    ReflectionAssert.assertReflectionEquals(session, session2);
}
 
Example 28
@Test
public void testCache() {
    SessionizerConfig config = new SessionizerConfig();
    config.setNativeMemoryInGB(1);
    config.setThreadNum(2);
    SessionMemoryCache store = new SessionMemoryCache(config);

    String guid = UUID.randomUUID().toString();
    String uid = "1:" + guid;
    Assert.assertNull(store.get(uid));
    Session session = new Session();
    session.setCreationTime(System.currentTimeMillis());
    Map<String, Object> initialAttributes = new HashMap<String, Object>();
    initialAttributes.put("1", "2");
    initialAttributes.put("2", "018a0a64206514f8eabaf3a83350373f");
    initialAttributes.put("3", 5);
    initialAttributes.put("4", "6");
    initialAttributes.put("5", "1.2.3.4");
    initialAttributes.put("6", "xyz");
    initialAttributes.put("7", "123234324");
    initialAttributes.put("8","xxxxxxx");
    initialAttributes.put("9", "123.123.234.123");
    initialAttributes.put("10", "8");
    session.setInitialAttributes(initialAttributes);
    Map<String, Object> dynamicAttributes = new HashMap<String, Object>();
    dynamicAttributes.put("11", "xx");
    session.setDynamicAttributes(dynamicAttributes);
    session.setIdentifier(guid);
    session.setType(1);
    store.put(uid, session);
    ReflectionAssert.assertReflectionEquals(session, store.get(uid));
    store.remove(uid, store.get(uid));
    Assert.assertNull(store.get(uid));
}
 
Example 29
@Test
public void testCache2() {
    SessionizerConfig config = new SessionizerConfig();
    config.setNativeMemoryInGB(1);
    config.setThreadNum(2);
    SessionMemoryCache store = new SessionMemoryCache(config);

    String guid = UUID.randomUUID().toString();
    String uid = "1:" + guid;
    Assert.assertNull(store.get(uid));
    Session session = new Session();
    session.setCreationTime(System.currentTimeMillis());
    Map<String, Object> initialAttributes = new HashMap<String, Object>();
    initialAttributes.put("1", "2");
    initialAttributes.put("2", "018a0a64206514f8eabaf3a83350373f");
    initialAttributes.put("3", 5);
    initialAttributes.put("4", "6");
    initialAttributes.put("5", "1.2.3.4");
    initialAttributes.put("6", "xyz");
    initialAttributes.put("7", "123234324");
    initialAttributes.put("8","xxxxxxx");
    initialAttributes.put("9", "123.123.234.123");
    initialAttributes.put("10", "8");
    session.setInitialAttributes(initialAttributes);
    Map<String, Object> dynamicAttributes = new HashMap<String, Object>();
    dynamicAttributes.put("11", "xx");
    session.setDynamicAttributes(dynamicAttributes);
    session.setIdentifier(guid);
    session.setType(1);
    store.put(uid, session);
    ReflectionAssert.assertReflectionEquals(session, store.get(uid));
    int maxItemSize = store.getMaxItemSize();
    Assert.assertTrue(maxItemSize > 0);
    store.removeFirst();
    store.resetMaxItemSize();
    maxItemSize = store.getMaxItemSize();
    Assert.assertTrue(maxItemSize == 0);
    Assert.assertNull(store.get(uid));
}
 
Example 30
@Test
public void test_list_of_servers() throws MarathonException {
    GetAppsResponse appsResponse = new GetAppsResponse();

    when(marathonClient.getApps())
            .thenReturn(appsResponse);

    appsResponse.setApps(new ArrayList<>());

    ReflectionAssert.assertReflectionEquals(
            "should be no one element",
            Collections.emptyList(),
            discoveryClient.getServices(),
            ReflectionComparatorMode.LENIENT_ORDER
    );

    //add first application
    VersionedApp app1 = new VersionedApp();
    app1.setId("app1");

    appsResponse.getApps().add(app1);

    ReflectionAssert.assertReflectionEquals(
            "should be only one element",
            Collections.singletonList("app1"),
            discoveryClient.getServices(),
            ReflectionComparatorMode.LENIENT_ORDER
    );

    //add another application
    VersionedApp app2 = new VersionedApp();
    app2.setId("app2");

    appsResponse.getApps().add(app2);

    ReflectionAssert.assertReflectionEquals(
            "should be two elements",
            IntStream.of(1,2)
                    .mapToObj(index -> "app" + index)
                    .collect(Collectors.toList()),
            discoveryClient.getServices(),
            ReflectionComparatorMode.LENIENT_ORDER
    );
}