Skip to content

Commit

Permalink
Fix tests for back up mechanism
Browse files Browse the repository at this point in the history
-Add mock call
-Replace old function calls for new

[#350]
  • Loading branch information
smcvb committed Nov 7, 2017
1 parent 110410c commit 386bc90
Showing 1 changed file with 14 additions and 13 deletions.
Expand Up @@ -34,6 +34,7 @@
import java.net.URI; import java.net.URI;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Optional;
import java.util.function.Predicate; import java.util.function.Predicate;


import static org.junit.Assert.*; import static org.junit.Assert.*;
Expand Down Expand Up @@ -80,6 +81,7 @@ public void setUp() throws Exception {
new MessageRoutingInformation(LOAD_FACTOR, COMMAND_NAME_FILTER, new XStreamSerializer()); new MessageRoutingInformation(LOAD_FACTOR, COMMAND_NAME_FILTER, new XStreamSerializer());


ResponseEntity<MessageRoutingInformation> responseEntity = mock(ResponseEntity.class); ResponseEntity<MessageRoutingInformation> responseEntity = mock(ResponseEntity.class);
when(responseEntity.hasBody()).thenReturn(true);
when(responseEntity.getBody()).thenReturn(expectedMessageRoutingInfo); when(responseEntity.getBody()).thenReturn(expectedMessageRoutingInfo);
when(restTemplate.exchange( when(restTemplate.exchange(
any(), eq(HttpMethod.GET), eq(HttpEntity.EMPTY), eq(MessageRoutingInformation.class) any(), eq(HttpMethod.GET), eq(HttpEntity.EMPTY), eq(MessageRoutingInformation.class)
Expand All @@ -106,36 +108,35 @@ public void testGetLocalMessageRoutingInformationReturnsMessageRoutingInformatio
} }


@Test @Test
public void testMessageRoutingInformationFromNonMetadataSourceReturnsLocalMessageRoutingInformationIfSimpleMemberIsLocal() public void testGetMessageRoutingInformationReturnsLocalMessageRoutingInformationIfSimpleMemberIsLocal()
throws Exception { throws Exception {
testSubject.updateMembership(LOAD_FACTOR, COMMAND_NAME_FILTER); testSubject.updateMembership(LOAD_FACTOR, COMMAND_NAME_FILTER);
//TODO Still needs a fix
Optional<MessageRoutingInformation> result = testSubject.getMessageRoutingInformation(serviceInstance);


MessageRoutingInformation result = assertTrue(result.isPresent());
testSubject.messageRoutingInformationFromNonMetadataSource(serviceInstance); assertEquals(expectedMessageRoutingInfo, result.get());

assertEquals(expectedMessageRoutingInfo, result);
} }


@Test(expected = IllegalArgumentException.class) @Test(expected = IllegalArgumentException.class)
public void testMessageRoutingInformationFromNonMetadataSourceThrowsIllegalArgumentExceptionIfEndpointIsMissing() public void testGetMessageRoutingInformationThrowsIllegalArgumentExceptionIfEndpointIsMissing() throws Exception {
throws Exception {
ServiceInstance remoteInstance = mock(ServiceInstance.class); ServiceInstance remoteInstance = mock(ServiceInstance.class);
when(remoteInstance.getServiceId()).thenReturn(SERVICE_INSTANCE_ID); when(remoteInstance.getServiceId()).thenReturn(SERVICE_INSTANCE_ID);
when(remoteInstance.getUri()).thenReturn(null); when(remoteInstance.getUri()).thenReturn(null);


testSubject.messageRoutingInformationFromNonMetadataSource(remoteInstance); testSubject.getMessageRoutingInformation(remoteInstance);
} }


@Test @Test
public void testMessageRoutingInformationFromNonMetadataSourceRequestMessageRoutingInformation() throws Exception { public void testGetMessageRoutingInformationRequestsMessageRoutingInformation() throws Exception {
ServiceInstance remoteInstance = mock(ServiceInstance.class); ServiceInstance remoteInstance = mock(ServiceInstance.class);
when(remoteInstance.getServiceId()).thenReturn(SERVICE_INSTANCE_ID); when(remoteInstance.getServiceId()).thenReturn(SERVICE_INSTANCE_ID);
when(remoteInstance.getUri()).thenReturn(URI.create("http://remote")); when(remoteInstance.getUri()).thenReturn(URI.create("http://remote"));


MessageRoutingInformation result = Optional<MessageRoutingInformation> result = testSubject.getMessageRoutingInformation(remoteInstance);
testSubject.messageRoutingInformationFromNonMetadataSource(remoteInstance);


assertEquals(expectedMessageRoutingInfo, result); assertTrue(result.isPresent());
assertEquals(expectedMessageRoutingInfo, result.get());


verify(restTemplate).exchange(uriArgumentCaptor.capture(), verify(restTemplate).exchange(uriArgumentCaptor.capture(),
eq(HttpMethod.GET), eq(HttpMethod.GET),
Expand Down Expand Up @@ -167,4 +168,4 @@ public void testUpdateMembershipsOnHeartbeatEventRequestsMessageRoutingInformati
eq(HttpEntity.EMPTY), eq(HttpEntity.EMPTY),
eq(MessageRoutingInformation.class)); eq(MessageRoutingInformation.class));
} }
} }

0 comments on commit 386bc90

Please sign in to comment.