Java Code Examples for org.unitils.reflectionassert.ReflectionAssert#assertReflectionEquals()

The following examples show how to use org.unitils.reflectionassert.ReflectionAssert#assertReflectionEquals() . 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 File: EasyBundlerTest.java    From easybundler with 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
Source File: AbstractBaseTest.java    From kripton with 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 3
Source File: AbstractBaseTest.java    From kripton with 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 4
Source File: AbstractBaseTest.java    From kripton with 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 5
Source File: AbstractBaseTest.java    From kripton with 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 6
Source File: MarathonServerListFetchZoneTests.java    From spring-cloud-marathon with MIT License 6 votes vote down vote up
@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 7
Source File: AbstractBaseTest.java    From kripton with 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 8
Source File: SessionCacheStoreTest.java    From realtime-analytics with GNU General Public License v2.0 5 votes vote down vote up
@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 9
Source File: Test45Runtime.java    From kripton with 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 10
Source File: Test45Runtime.java    From kripton with 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 11
Source File: AbstractBindTypeProcessorTest.java    From kripton with 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 12
Source File: BaseProcessorTest.java    From kripton with 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 13
Source File: MarathonServerListIgnoreServiceIdTests.java    From spring-cloud-marathon with 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 14
Source File: SessionSerializerTest.java    From realtime-analytics with GNU General Public License v2.0 5 votes vote down vote up
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 15
Source File: MarathonServerListByLabelTests.java    From spring-cloud-marathon with 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 16
Source File: MarathonServerListByLabelTests.java    From spring-cloud-marathon with 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 17
Source File: MarathonServerListTests.java    From spring-cloud-marathon with 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 18
Source File: AbstractBindTypeProcessorTest.java    From kripton with Apache License 2.0 4 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);
	System.out.println(output2);

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

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

	return output2.length();
}
 
Example 19
Source File: MarathonDiscoveryClientTests.java    From spring-cloud-marathon with MIT License 4 votes vote down vote up
@Test
public void test_list_of_instances() throws MarathonException {
    GetAppResponse appResponse = new GetAppResponse();

    when(marathonClient.getApp("/app1"))
            .thenReturn(appResponse);

    appResponse.setApp(new VersionedApp());
    appResponse.getApp().setTasks(new ArrayList<>());

    Task taskWithNoHealthChecks = new Task();
    taskWithNoHealthChecks.setAppId("/app1");
    taskWithNoHealthChecks.setHost("host1");
    taskWithNoHealthChecks.setPorts(
            IntStream.of(9090)
            .boxed()
            .collect(Collectors.toList())
    );

    appResponse.getApp().getTasks().add(taskWithNoHealthChecks);

    Task taskWithAllGoodHealthChecks = new Task();
    taskWithAllGoodHealthChecks.setAppId("/app1");
    taskWithAllGoodHealthChecks.setHost("host2");
    taskWithAllGoodHealthChecks.setPorts(
            IntStream.of(9090, 9091)
                    .boxed()
                    .collect(Collectors.toList())
    );

    HealthCheckResults healthCheckResult = new HealthCheckResults();
    healthCheckResult.setAlive(true);

    HealthCheckResults badHealthCheckResult = new HealthCheckResults();
    badHealthCheckResult.setAlive(false);

    List<HealthCheckResults> healthCheckResults = new ArrayList<>();
    healthCheckResults.add(healthCheckResult);
    healthCheckResults.add(healthCheckResult);

    taskWithAllGoodHealthChecks.setHealthCheckResults(healthCheckResults);

    appResponse.getApp().getTasks().add(taskWithAllGoodHealthChecks);

    Task taskWithOneBadHealthCheck = new Task();
    taskWithOneBadHealthCheck.setAppId("/app1");
    taskWithOneBadHealthCheck.setHost("host3");
    taskWithOneBadHealthCheck.setPorts(
            IntStream.of(9090)
                    .boxed()
                    .collect(Collectors.toList())
    );

    List<HealthCheckResults> withBadHealthCheckResults = new ArrayList<>();
    withBadHealthCheckResults.add(healthCheckResult);
    withBadHealthCheckResults.add(badHealthCheckResult);

    taskWithOneBadHealthCheck.setHealthCheckResults(withBadHealthCheckResults);

    appResponse.getApp().getTasks().add(taskWithOneBadHealthCheck);

    ReflectionAssert.assertReflectionEquals(
            "should be two tasks",
            IntStream.of(1,2)
                .mapToObj(index ->
                        new DefaultServiceInstance(
                            "app1",
                            "host" + index,
                            9090,
                            false
                        )
                ).collect(Collectors.toList()),
            discoveryClient.getInstances("app1"),
            ReflectionComparatorMode.LENIENT_ORDER
    );
}
 
Example 20
Source File: MarathonDiscoveryClientTests.java    From spring-cloud-marathon with MIT License 4 votes vote down vote up
@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
    );
}