@Test
public void init_shouldNotInitializeCADI_whenAafIsNotUsed() throws Exception {
//given
- doReturn("false").when(dmaapConfig).getProperty(eq(AAFAuthenticationFilter.AAF_AUTHN_FLAG), anyString());
+ doReturn("false").when(dmaapConfig).getProperty(eq(AAFAuthenticationFilter.CADI_AUTHN_FLAG), anyString());
//when
filter.init(filterConfig);
//then
- assertFalse(filter.isAafEnabled());
+ assertFalse(filter.isCadiEnabled());
assertNull(filter.getCadiFilter());
}
@Test
public void doFilter_shouldSkipCADI_whenAafIsNotUsed() throws Exception {
//given
- doReturn("false").when(dmaapConfig).getProperty(eq(AAFAuthenticationFilter.AAF_AUTHN_FLAG), anyString());
+ doReturn("false").when(dmaapConfig).getProperty(eq(AAFAuthenticationFilter.CADI_AUTHN_FLAG), anyString());
filter.init(filterConfig);
filter.setCadiFilter(cadiFilterMock);
@Test
public void init_shouldFail_whenAafIsUsed_andCadiPropertiesHasNotBeenSet() throws Exception {
//given
- doReturn("true").when(dmaapConfig).getProperty(eq(AAFAuthenticationFilter.AAF_AUTHN_FLAG), anyString());
+ doReturn("true").when(dmaapConfig).getProperty(eq(AAFAuthenticationFilter.CADI_AUTHN_FLAG), anyString());
doReturn("").when(dmaapConfig).getProperty(AAFAuthenticationFilter.CADI_PROPERTIES);
//then
}
@Test
- public void init_shouldInitializeCADI_whenAafIsUsed_andCadiPropertiesSet() throws Exception {
+ public void init_shouldFail_whenAafIsUsed_andInvalidCadiPropertiesSet() throws Exception {
//given
- doReturn("true").when(dmaapConfig).getProperty(eq(AAFAuthenticationFilter.AAF_AUTHN_FLAG), anyString());
- doReturn("cadi.properties").when(dmaapConfig).getProperty(AAFAuthenticationFilter.CADI_PROPERTIES);
+ String invalidFilePath = "src/test/resources/notExisting.properties";
+ doReturn("true").when(dmaapConfig).getProperty(eq(AAFAuthenticationFilter.CADI_AUTHN_FLAG), anyString());
+ doReturn(invalidFilePath).when(dmaapConfig).getProperty(AAFAuthenticationFilter.CADI_PROPERTIES);
+
+ //then
+ thrown.expect(ServletException.class);
+ thrown.expectMessage("Could not load CADI properties file: "+invalidFilePath);
+
+ //when
+ filter.init(filterConfig);
+ }
+
+ /*
+ * See https://jira.onap.org/browse/DMAAP-1361 for why this is commented out
+ @Test
+ public void init_shouldInitializeCADI_whenAafIsUsed_andValidCadiPropertiesSet() throws Exception {
+ //given
+ doReturn("true").when(dmaapConfig).getProperty(eq(AAFAuthenticationFilter.CADI_AUTHN_FLAG), anyString());
+ doReturn("src/test/resources/cadi.properties").when(dmaapConfig).getProperty(AAFAuthenticationFilter.CADI_PROPERTIES);
//when
filter.init(filterConfig);
//then
- assertTrue(filter.isAafEnabled());
+ assertTrue(filter.isCadiEnabled());
assertNotNull(filter.getCadiFilter());
}
}
private void initCADIFilter() throws Exception{
- doReturn("true").when(dmaapConfig).getProperty(eq(AAFAuthenticationFilter.AAF_AUTHN_FLAG), anyString());
- doReturn("cadi.properties").when(dmaapConfig).getProperty(AAFAuthenticationFilter.CADI_PROPERTIES);
+ doReturn("true").when(dmaapConfig).getProperty(eq(AAFAuthenticationFilter.CADI_AUTHN_FLAG), anyString());
+ doReturn("src/test/resources/cadi.properties").when(dmaapConfig).getProperty(AAFAuthenticationFilter.CADI_PROPERTIES);
filter.init(filterConfig);
filter.setCadiFilter(cadiFilterMock);
}
-
+*/
}
\ No newline at end of file