BaseService { protected AssertionType getAssertion(WebServiceContext context) { return getAssertion(context, null); }  Properties getWebContextProperties(WebServiceContext context);  }
@Test public void testReadHttpHeaders_ReadOff() throws PropertyAccessException { final PropertyAccessor mockPropAccessor = mock(PropertyAccessor.class); TestService testService = new TestService() { @Override protected PropertyAccessor getPropertyAccessor() { return mockPropAccessor; } }; AssertionType resultAssertion = new AssertionType(); when(mockPropAccessor.getPropertyBoolean(NhincConstants.GATEWAY_PROPERTY_FILE, NhincConstants.READ_HTTP_HEADERS)).thenReturn(Boolean.FALSE); testService.getAssertion(resultAssertion); List<CONNECTCustomHttpHeadersType> resultHeaders = resultAssertion.getCONNECTCustomHttpHeaders(); assert(resultHeaders.isEmpty()); }
@Test public void testReadHttpHeaders_ReadsTwoValues() throws PropertyAccessException { final PropertyAccessor mockPropAccessor = mock(PropertyAccessor.class); final MessageImpl mockMessage = mock(MessageImpl.class); final WrappedMessageContext messageContext = new WrappedMessageContext(mockMessage); TestService testService = new TestService() { @Override protected PropertyAccessor getPropertyAccessor() { return mockPropAccessor; } @Override protected MessageContext getMessageContext(WebServiceContext context) { return messageContext; } }; AssertionType resultAssertion = new AssertionType(); when(mockPropAccessor.getPropertyBoolean(NhincConstants.GATEWAY_PROPERTY_FILE, NhincConstants.READ_HTTP_HEADERS)).thenReturn(Boolean.TRUE); when(mockMessage.get(Message.PROTOCOL_HEADERS)).thenReturn(happyHeaders); testService.getAssertion(resultAssertion); List<CONNECTCustomHttpHeadersType> resultHeaders = resultAssertion.getCONNECTCustomHttpHeaders(); assertNotNull(resultHeaders); assertEquals(resultAssertion.getCONNECTCustomHttpHeaders().size(), happyHeaders.size()); assert(happyHeaders.keySet().contains(resultHeaders.get(0).getHeaderName())); assert(happyHeaders.keySet().contains(resultHeaders.get(1).getHeaderName())); }
@Test public void testReadHttpHeaders_FilterDefaultHeader() throws PropertyAccessException { final PropertyAccessor mockPropAccessor = mock(PropertyAccessor.class); final MessageImpl mockMessage = mock(MessageImpl.class); final WrappedMessageContext messageContext = new WrappedMessageContext(mockMessage); TestService testService = new TestService() { @Override protected PropertyAccessor getPropertyAccessor() { return mockPropAccessor; } @Override protected MessageContext getMessageContext(WebServiceContext context) { return messageContext; } }; AssertionType resultAssertion = new AssertionType(); when(mockPropAccessor.getPropertyBoolean(NhincConstants.GATEWAY_PROPERTY_FILE, NhincConstants.READ_HTTP_HEADERS)).thenReturn(Boolean.TRUE); when(mockMessage.get(Message.PROTOCOL_HEADERS)).thenReturn(filterHeaders); testService.getAssertion(resultAssertion); List<CONNECTCustomHttpHeadersType> resultHeaders = resultAssertion.getCONNECTCustomHttpHeaders(); assertNotNull(resultHeaders); assertEquals(resultAssertion.getCONNECTCustomHttpHeaders().size(), filterHeaders.size() - 1); boolean containsDefaultHeader = false; for(CONNECTCustomHttpHeadersType header : resultHeaders) { if(header.getHeaderName().equals(HEADER_NAME_CONNECTION)) { containsDefaultHeader = true; break; } } assertFalse(containsDefaultHeader); }