From 27da2e3395b009702c9032f9fa184f253747c8a7 Mon Sep 17 00:00:00 2001 From: Shawn Severin Date: Fri, 8 Dec 2017 08:57:17 -0500 Subject: Adding back-end support for UI filters Issue-ID: AAI-543 Change-Id: I15b7ef1a9d4091981444019b5cceac08c4045c51 Signed-off-by: Shawn Severin --- .../sparky/search/filters/FilterProcessorTest.java | 373 +++++++++++++++++++++ .../search/filters/FilteredSearchHelperTest.java | 69 ++++ .../filters/entity/DiscoverFiltersRequest.java | 40 +++ .../search/filters/entity/ViewConfiguration.java | 68 ++++ .../sparky/search/filters/entity/ViewFilter.java | 57 ++++ ...estionEntity_getIndexDocumentJson_expected.json | 1 + src/test/resources/filters/aaiui_filters.json | 88 +++++ src/test/resources/filters/aaiui_views.json | 38 +++ ...Endpoint_emptyRequestBody_expectedResponse.json | 1 + ...t_emptyRequestFilterArray_expectedResponse.json | 1 + ...dpoint_emptyRequestFilterArray_requestBody.json | 3 + ...ationEndpoint_successPath_expectedResponse.json | 1 + ...gationEndpoint_successPath_operationResult.json | 1 + ...ggregationEndpoint_successPath_requestBody.json | 11 + 14 files changed, 752 insertions(+) create mode 100644 src/test/java/org/onap/aai/sparky/search/filters/FilterProcessorTest.java create mode 100644 src/test/java/org/onap/aai/sparky/search/filters/FilteredSearchHelperTest.java create mode 100644 src/test/java/org/onap/aai/sparky/search/filters/entity/DiscoverFiltersRequest.java create mode 100644 src/test/java/org/onap/aai/sparky/search/filters/entity/ViewConfiguration.java create mode 100644 src/test/java/org/onap/aai/sparky/search/filters/entity/ViewFilter.java create mode 100644 src/test/resources/filters/AggregationSuggestionEntity_getIndexDocumentJson_expected.json create mode 100644 src/test/resources/filters/aaiui_filters.json create mode 100644 src/test/resources/filters/aaiui_views.json create mode 100644 src/test/resources/filters/filterAggregationEndpoint_emptyRequestBody_expectedResponse.json create mode 100644 src/test/resources/filters/filterAggregationEndpoint_emptyRequestFilterArray_expectedResponse.json create mode 100644 src/test/resources/filters/filterAggregationEndpoint_emptyRequestFilterArray_requestBody.json create mode 100644 src/test/resources/filters/filterAggregationEndpoint_successPath_expectedResponse.json create mode 100644 src/test/resources/filters/filterAggregationEndpoint_successPath_operationResult.json create mode 100644 src/test/resources/filters/filterAggregationEndpoint_successPath_requestBody.json (limited to 'src/test') diff --git a/src/test/java/org/onap/aai/sparky/search/filters/FilterProcessorTest.java b/src/test/java/org/onap/aai/sparky/search/filters/FilterProcessorTest.java new file mode 100644 index 0000000..a6c4f22 --- /dev/null +++ b/src/test/java/org/onap/aai/sparky/search/filters/FilterProcessorTest.java @@ -0,0 +1,373 @@ +/** + * ============LICENSE_START=================================================== SPARKY (AAI UI + * service) ============================================================================ Copyright © + * 2017 AT&T Intellectual Property. Copyright © 2017 Amdocs All rights reserved. + * ============================================================================ Licensed under the + * Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. ============LICENSE_END===================================================== + * + * ECOMP and OpenECOMP are trademarks and service marks of AT&T Intellectual Property. + */ + +package org.onap.aai.sparky.search.filters; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.io.IOException; +import java.io.StringReader; +import java.util.ArrayList; +import java.util.List; + +import javax.json.Json; +import javax.json.JsonArray; +import javax.json.JsonObject; +import javax.json.JsonReader; + +import org.apache.camel.Exchange; +import org.apache.camel.Message; +import org.apache.camel.component.restlet.RestletConstants; +import org.junit.Before; +import org.junit.Test; +import org.mockito.ArgumentCaptor; +import org.mockito.Mockito; +import org.onap.aai.sparky.search.filters.FilterProcessor; +import org.onap.aai.sparky.search.filters.FilteredSearchHelper; +import org.onap.aai.sparky.search.filters.config.UiFilterConfig; +import org.onap.aai.sparky.search.filters.config.UiFilterListItemConfig; +import org.onap.aai.sparky.search.filters.config.UiFilterOptionsValuesConfig; +import org.onap.aai.sparky.search.filters.config.FiltersDetailsConfig; +import org.onap.aai.sparky.search.filters.config.FiltersConfig; +import org.onap.aai.sparky.search.filters.config.UiViewListItemConfig; +import org.onap.aai.sparky.search.filters.entity.DiscoverFiltersRequest; +import org.onap.aai.sparky.search.filters.entity.ViewConfiguration; +import org.onap.aai.sparky.search.filters.entity.ViewFilter; +import org.onap.aai.sparky.util.NodeUtils; +import org.onap.aai.sparky.search.filters.config.FiltersForViewsConfig; +import org.restlet.Request; +import org.restlet.Response; +import org.restlet.data.MediaType; +import org.restlet.data.Status; + +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; + +public class FilterProcessorTest { + + private FilterProcessor filterProcessor; + private Exchange mockExchange; + private Message mockRequestMessage; + private Message mockResponseMessage; + private Request mockRestletRequest; + private Response mockRestletResponse; + private FilteredSearchHelper filteredSearchHelper; + private ObjectMapper mapper; + + protected UiViewListItemConfig generateViewConfig(ViewConfiguration viewConfig) { + + UiViewListItemConfig uiViewConfig = new UiViewListItemConfig(viewConfig.getViewName(), null); + + List filters = new ArrayList(); + + for (ViewFilter viewFilter : viewConfig.getViewFilters()) { + filters.add(new UiFilterListItemConfig(viewFilter.getId(), viewFilter.getDefaultValue())); + } + + uiViewConfig.setListOfFilters(filters); + + return uiViewConfig; + } + + protected FiltersConfig generateDefaultViewsFilterConfig() { + + FiltersForViewsConfig uiViewsConfig = new FiltersForViewsConfig(); + FiltersConfig viewFilterConfig = FiltersConfig.getInstance(); + + List views = new ArrayList(); + + // Default filter value to use below + UiFilterOptionsValuesConfig defaultValue = + new UiFilterOptionsValuesConfig("Today", "Last 0 hours"); + + // VNF View - 4 Filters + ViewConfiguration vnfViewConfig = new ViewConfiguration("vnfSearch"); + vnfViewConfig.addViewFilter(new ViewFilter("1", null)); + vnfViewConfig.addViewFilter(new ViewFilter("2", null)); + vnfViewConfig.addViewFilter(new ViewFilter("7", null)); + vnfViewConfig.addViewFilter(new ViewFilter("8", null)); + views.add(generateViewConfig(vnfViewConfig)); + + // View and Inspect (Schema) - 0 Filters + ViewConfiguration viewInspectConfig = new ViewConfiguration("viewInspect"); + views.add(generateViewConfig(viewInspectConfig)); + + // Data Integrity - 4 Filters + ViewConfiguration dataIntegrityConfig = new ViewConfiguration("dataIntegrity"); + dataIntegrityConfig.addViewFilter(new ViewFilter("3", null)); + dataIntegrityConfig.addViewFilter(new ViewFilter("4", null)); + dataIntegrityConfig.addViewFilter(new ViewFilter("5", defaultValue)); + dataIntegrityConfig.addViewFilter(new ViewFilter("6", null)); + views.add(generateViewConfig(dataIntegrityConfig)); + + uiViewsConfig.setViews(views); + + viewFilterConfig.setViewsConfig(uiViewsConfig); + + List optionsValues = new ArrayList(); + optionsValues.add(new UiFilterOptionsValuesConfig("Today", "Last 0 hours")); + optionsValues.add(new UiFilterOptionsValuesConfig("Since Yesterday", "Last 24 hours")); + optionsValues.add(new UiFilterOptionsValuesConfig("Since Last Week", "Last 7 days")); + optionsValues.add(new UiFilterOptionsValuesConfig("Since Last Month", "Last 30 days")); + optionsValues.add(new UiFilterOptionsValuesConfig("Custom Range", "Custom Range")); + + + + FiltersDetailsConfig uiFiltersConfig = new FiltersDetailsConfig(); + + List uiFilterConfig = new ArrayList(); + uiFilterConfig.add(new UiFilterConfig("1", "filterName1", "Display Name 1", "dropDown", "false", + "Any 1", null, "options", null, null)); + uiFilterConfig.add(new UiFilterConfig("2", "filterName2", "Display Name 2", "dropDown", "false", + "Any 2", null, "options", null, null)); + uiFilterConfig.add(new UiFilterConfig("3", "filterName3", "Display Name 3", "dropDown", "false", + "Any 3", null, "options", null, null)); + uiFilterConfig.add(new UiFilterConfig("4", "filterName4", "Display Name 4", "dropDown", "false", + "Any 4", null, "options", null, null)); + uiFilterConfig.add(new UiFilterConfig("5", "filterName5", "Display Name 5", "date", "false", + "Any 5", defaultValue, "dynamicOptions", optionsValues, null)); + uiFilterConfig.add(new UiFilterConfig("6", "filterName6", "Display Name 6", "dropDown", "false", + "Any 6", null, "options", null, null)); + uiFilterConfig.add(new UiFilterConfig("7", "filterName7", "Display Name 7", "dropDown", "false", + "Any 7", null, "options", null, null)); + uiFilterConfig.add(new UiFilterConfig("8", "filterName8", "Display Name 8", "dropDown", "false", + "Any 8", null, "options", null, null)); + + uiFiltersConfig.setFilters(uiFilterConfig); + + viewFilterConfig.setFiltersConfig(uiFiltersConfig); + + return viewFilterConfig; + } + + @Before + public void init() { + mockExchange = Mockito.mock(Exchange.class); + mockRequestMessage = Mockito.mock(Message.class); + mockResponseMessage = Mockito.mock(Message.class); + mockRestletRequest = Mockito.mock(Request.class); + mockRestletResponse = Mockito.mock(Response.class); + + filteredSearchHelper = new FilteredSearchHelper(generateDefaultViewsFilterConfig()); + filterProcessor = new FilterProcessor(filteredSearchHelper); + + mapper = new ObjectMapper(); + } + + + @Test + public void validateDefaultConstructor() { + assertNotNull(filterProcessor.getMapper()); + assertNotNull(filterProcessor.getFilteredSearchHelper()); + } + + private void verifyResponseAndNumFiltersForBadRequest(Status expectedStatus, + int numExpectedFilters) throws JsonParseException, JsonMappingException, IOException { + + ArgumentCaptor responseCodeCaptor = ArgumentCaptor.forClass(Status.class); + Mockito.verify(mockRestletResponse, Mockito.atLeast(1)).setStatus(responseCodeCaptor.capture()); + assertEquals(expectedStatus, responseCodeCaptor.getValue()); + + ArgumentCaptor entityPayload = ArgumentCaptor.forClass(String.class); + ArgumentCaptor payloadMediaType = ArgumentCaptor.forClass(MediaType.class); + Mockito.verify(mockRestletResponse, Mockito.atLeast(1)).setEntity(entityPayload.capture(), + payloadMediaType.capture()); + assertNotNull(entityPayload.getValue()); + + ArgumentCaptor responseObject = ArgumentCaptor.forClass(Response.class); + Mockito.verify(mockResponseMessage, Mockito.atLeast(1)).setBody(responseObject.capture()); + assertEquals(MediaType.APPLICATION_JSON, payloadMediaType.getValue()); + + JsonReader jsonReader = Json.createReader(new StringReader(entityPayload.getValue())); + JsonObject responsePayload = jsonReader.readObject(); + + JsonObject filters = responsePayload.getJsonObject("filters"); + assertEquals(0, filters.size()); + } + + private void initializeMocks(String requestPayload) { + + Mockito.when(mockRequestMessage.getBody(String.class)).thenReturn(requestPayload); + + Mockito.when(mockExchange.getIn()).thenReturn(mockRequestMessage); + Mockito.when(mockExchange.getOut()).thenReturn(mockResponseMessage); + + Mockito.when(mockRequestMessage.getHeader(RestletConstants.RESTLET_REQUEST, Request.class)) + .thenReturn(mockRestletRequest); + Mockito.when(mockRequestMessage.getHeader(RestletConstants.RESTLET_RESPONSE, Response.class)) + .thenReturn(mockRestletResponse); + } + + + @Test + public void testGetFiltersWithValues_success_path() throws IOException { + + // Initialize for call against 'vnfSearch' + DiscoverFiltersRequest vnfSearchrequest = new DiscoverFiltersRequest(); + vnfSearchrequest.setViewName("vnfSearch"); + + initializeMocks(NodeUtils.convertObjectToJson(vnfSearchrequest, false)); + + // Test call against 'vnfSearch' + filterProcessor.getFiltersWithValues(mockExchange); + + ArgumentCaptor vnfResponseCodeCaptor = ArgumentCaptor.forClass(Status.class); + Mockito.verify(mockRestletResponse, Mockito.atLeast(1)) + .setStatus(vnfResponseCodeCaptor.capture()); + assertEquals(Status.SUCCESS_OK, vnfResponseCodeCaptor.getValue()); + + ArgumentCaptor vnfEntityPayload = ArgumentCaptor.forClass(String.class); + ArgumentCaptor vnfPayloadMediaType = ArgumentCaptor.forClass(MediaType.class); + Mockito.verify(mockRestletResponse, Mockito.atLeast(1)).setEntity(vnfEntityPayload.capture(), + vnfPayloadMediaType.capture()); + assertNotNull(vnfEntityPayload.getValue()); + + ArgumentCaptor vnfResponseObject = ArgumentCaptor.forClass(Response.class); + Mockito.verify(mockResponseMessage, Mockito.atLeast(1)).setBody(vnfResponseObject.capture()); + assertEquals(MediaType.APPLICATION_JSON, vnfPayloadMediaType.getValue()); + + JsonReader vnfJsonReader = Json.createReader(new StringReader(vnfEntityPayload.getValue())); + JsonObject vnfResponsePayload = vnfJsonReader.readObject(); + + JsonObject vnfFilters = vnfResponsePayload.getJsonObject("filters"); + assertNotNull(vnfFilters); + assertEquals(4, vnfFilters.size()); + + JsonObject filterOne = vnfFilters.getJsonObject("1"); + assertNotNull(filterOne); + assertEquals("Display Name 1", filterOne.getString("label")); + + JsonObject filterEight = vnfFilters.getJsonObject("8"); + assertNotNull(filterEight); + JsonObject eightInnerControl = + filterEight.getJsonObject("controls").getJsonObject("filterName8"); + assertEquals(4, eightInnerControl.size()); + assertEquals("dropDown", eightInnerControl.getString("type")); + assertEquals("false", eightInnerControl.getString("multiSelect")); + assertEquals("Any 8", eightInnerControl.getString("watermark")); + assertEquals(0, eightInnerControl.getJsonArray("options").size()); + + // Initialize for call against 'dataIntegrity' + DiscoverFiltersRequest dataIntegrityRequest = new DiscoverFiltersRequest(); + dataIntegrityRequest.setViewName("dataIntegrity"); + + initializeMocks(NodeUtils.convertObjectToJson(dataIntegrityRequest, false)); + + // Test call against 'dataIntegrity' + filterProcessor.getFiltersWithValues(mockExchange); + + ArgumentCaptor dIResponseCodeCaptor = ArgumentCaptor.forClass(Status.class); + Mockito.verify(mockRestletResponse, Mockito.atLeast(1)) + .setStatus(dIResponseCodeCaptor.capture()); + assertEquals(Status.SUCCESS_OK, dIResponseCodeCaptor.getValue()); + + ArgumentCaptor dIEntityPayload = ArgumentCaptor.forClass(String.class); + ArgumentCaptor dIPayloadMediaType = ArgumentCaptor.forClass(MediaType.class); + Mockito.verify(mockRestletResponse, Mockito.atLeast(1)).setEntity(dIEntityPayload.capture(), + dIPayloadMediaType.capture()); + assertNotNull(dIEntityPayload.getValue()); + + ArgumentCaptor dIResponseObject = ArgumentCaptor.forClass(Response.class); + Mockito.verify(mockResponseMessage, Mockito.atLeast(1)).setBody(dIResponseObject.capture()); + assertEquals(MediaType.APPLICATION_JSON, dIPayloadMediaType.getValue()); + + JsonReader dIJsonReader = Json.createReader(new StringReader(dIEntityPayload.getValue())); + JsonObject dIResponsePayload = dIJsonReader.readObject(); + + JsonObject dIFilters = dIResponsePayload.getJsonObject("filters"); + assertNotNull(dIFilters); + assertEquals(4, dIFilters.size()); + + JsonObject filterFour = dIFilters.getJsonObject("4"); + assertNotNull(filterFour); + assertEquals("Display Name 4", filterFour.getString("label")); + + JsonObject filterFive = dIFilters.getJsonObject("5"); + assertNotNull(filterFive); + JsonObject fiveInnerControl = filterFive.getJsonObject("controls").getJsonObject("filterName5"); + assertEquals(5, fiveInnerControl.size()); + assertEquals("date", fiveInnerControl.getString("type")); + assertEquals("false", fiveInnerControl.getString("multiSelect")); + assertEquals("Any 5", fiveInnerControl.getString("watermark")); + JsonArray dynamicOptions = fiveInnerControl.getJsonArray("dynamicOptions"); + assertEquals(5, dynamicOptions.size()); + JsonObject today = dynamicOptions.getJsonObject(0); + assertEquals("Today", today.getString("decode")); + } + + @Test + public void testGetFiltersWithValues_viewNameNull() throws IOException { + + DiscoverFiltersRequest discoverFiltersRequest = new DiscoverFiltersRequest(); + initializeMocks(NodeUtils.convertObjectToJson(discoverFiltersRequest, false)); + + // Method under test + filterProcessor.getFiltersWithValues(mockExchange); + + verifyResponseAndNumFiltersForBadRequest(Status.SUCCESS_OK, 0); + } + + @Test + public void testGetFiltersWithValues_viewNameEmptyString() throws IOException { + + DiscoverFiltersRequest discoverFiltersRequest = new DiscoverFiltersRequest(); + discoverFiltersRequest.setViewName(""); + + initializeMocks(NodeUtils.convertObjectToJson(discoverFiltersRequest, false)); + + // Method under test + filterProcessor.getFiltersWithValues(mockExchange); + + verifyResponseAndNumFiltersForBadRequest(Status.SUCCESS_OK, 0); + } + + @Test + public void testGetFiltersWithValues_requestPayloadIsNull() throws IOException { + + initializeMocks(null); + + // Method under test + filterProcessor.getFiltersWithValues(mockExchange); + + verifyResponseAndNumFiltersForBadRequest(Status.SUCCESS_OK, 0); + } + + @Test + public void testGetFiltersWithValues_requestPayloadIsEmptyString() throws IOException { + + initializeMocks(""); + + // Method under test + filterProcessor.getFiltersWithValues(mockExchange); + + verifyResponseAndNumFiltersForBadRequest(Status.SUCCESS_OK, 0); + } + + @Test + public void testGetFiltersWithValues_requestPayloadCausesException() throws IOException { + + initializeMocks("{"); + + // Method under test + filterProcessor.getFiltersWithValues(mockExchange); + + verifyResponseAndNumFiltersForBadRequest(Status.SUCCESS_OK, 0); + } +} diff --git a/src/test/java/org/onap/aai/sparky/search/filters/FilteredSearchHelperTest.java b/src/test/java/org/onap/aai/sparky/search/filters/FilteredSearchHelperTest.java new file mode 100644 index 0000000..aa37d42 --- /dev/null +++ b/src/test/java/org/onap/aai/sparky/search/filters/FilteredSearchHelperTest.java @@ -0,0 +1,69 @@ +/** + * ============LICENSE_START=================================================== + * SPARKY (AAI UI service) + * ============================================================================ + * Copyright © 2017 AT&T Intellectual Property. + * Copyright © 2017 Amdocs + * All rights reserved. + * ============================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END===================================================== + * + * ECOMP and OpenECOMP are trademarks + * and service marks of AT&T Intellectual Property. + */ + +package org.onap.aai.sparky.search.filters; + +import static org.junit.Assert.assertEquals; + +import java.io.IOException; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.onap.aai.sparky.search.filters.FilteredSearchHelper; +import org.onap.aai.sparky.search.filters.config.FiltersConfig; + +public class FilteredSearchHelperTest { + + private static FilteredSearchHelper filteredSearchHelper; + + @BeforeClass + public static void init() throws IOException { + FiltersConfig config = FiltersConfig.getInstance(); + config.setFilterMappingsFileName("src/test/resources/filters/aaiui_views.json"); + config.setFiltersFileName("src/test/resources/filters/aaiui_filters.json"); + System.out.println("SETTING UIVIEWSCONFIG"); + config.setViewsConfig(config.readUiViewsConfig()); + System.out.println("SETTING UIFILTERSCONFIG"); + config.setFiltersConfig(config.readUiFiltersConfig()); + + filteredSearchHelper = new FilteredSearchHelper(config); + } + + @Test + public void testDoFilterDiscovery_validViewName() { + assertEquals(4, filteredSearchHelper.doFilterDiscovery("vnfSearch").getFilters().size()); + assertEquals(4, filteredSearchHelper.doFilterDiscovery("dataIntegrity").getFilters().size()); + } + + @Test + public void testDoFilterDiscovery_invalidViewName_nameGiven() { + assertEquals(0, filteredSearchHelper.doFilterDiscovery("InvalidViewName").getFilters().size()); + } + + @Test + public void testDoFilterDiscovery_invalidViewName_emptyString() { + assertEquals(0, filteredSearchHelper.doFilterDiscovery("").getFilters().size()); + } +} diff --git a/src/test/java/org/onap/aai/sparky/search/filters/entity/DiscoverFiltersRequest.java b/src/test/java/org/onap/aai/sparky/search/filters/entity/DiscoverFiltersRequest.java new file mode 100644 index 0000000..336e3b1 --- /dev/null +++ b/src/test/java/org/onap/aai/sparky/search/filters/entity/DiscoverFiltersRequest.java @@ -0,0 +1,40 @@ +/** + * ============LICENSE_START=================================================== + * SPARKY (AAI UI service) + * ============================================================================ + * Copyright © 2017 AT&T Intellectual Property. + * Copyright © 2017 Amdocs + * All rights reserved. + * ============================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END===================================================== + * + * ECOMP and OpenECOMP are trademarks + * and service marks of AT&T Intellectual Property. + */ + +package org.onap.aai.sparky.search.filters.entity; + +public class DiscoverFiltersRequest { + + private String viewName; + + public String getViewName() { + return viewName; + } + + public void setViewName(String viewName) { + this.viewName = viewName; + } + +} diff --git a/src/test/java/org/onap/aai/sparky/search/filters/entity/ViewConfiguration.java b/src/test/java/org/onap/aai/sparky/search/filters/entity/ViewConfiguration.java new file mode 100644 index 0000000..f6c352b --- /dev/null +++ b/src/test/java/org/onap/aai/sparky/search/filters/entity/ViewConfiguration.java @@ -0,0 +1,68 @@ +/** + * ============LICENSE_START=================================================== + * SPARKY (AAI UI service) + * ============================================================================ + * Copyright © 2017 AT&T Intellectual Property. + * Copyright © 2017 Amdocs + * All rights reserved. + * ============================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END===================================================== + * + * ECOMP and OpenECOMP are trademarks + * and service marks of AT&T Intellectual Property. + */ + +package org.onap.aai.sparky.search.filters.entity; + +import java.util.ArrayList; +import java.util.List; + +public class ViewConfiguration { + + private String viewName; + private List viewFilters; + + public ViewConfiguration() { + viewFilters = new ArrayList(); + } + + public ViewConfiguration(String viewName) { + viewFilters = new ArrayList(); + this.setViewName(viewName); + } + + public String getViewName() { + return viewName; + } + + public void setViewName(String viewName) { + this.viewName = viewName; + } + + public List getViewFilters() { + return viewFilters; + } + + public void setViewFilters(List viewFilters) { + this.viewFilters = viewFilters; + } + + public void addViewFilter(ViewFilter viewFilter) { + if (viewFilters != null) { + if (!viewFilters.contains(viewFilter)) { + viewFilters.add(viewFilter); + } + } + } +} diff --git a/src/test/java/org/onap/aai/sparky/search/filters/entity/ViewFilter.java b/src/test/java/org/onap/aai/sparky/search/filters/entity/ViewFilter.java new file mode 100644 index 0000000..94832d5 --- /dev/null +++ b/src/test/java/org/onap/aai/sparky/search/filters/entity/ViewFilter.java @@ -0,0 +1,57 @@ +/** + * ============LICENSE_START=================================================== + * SPARKY (AAI UI service) + * ============================================================================ + * Copyright © 2017 AT&T Intellectual Property. + * Copyright © 2017 Amdocs + * All rights reserved. + * ============================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END===================================================== + * + * ECOMP and OpenECOMP are trademarks + * and service marks of AT&T Intellectual Property. + */ + +package org.onap.aai.sparky.search.filters.entity; + +import org.onap.aai.sparky.search.filters.config.UiFilterOptionsValuesConfig; + +public class ViewFilter { + + private String id; + private UiFilterOptionsValuesConfig defaultValue; + + public ViewFilter() {} + + public ViewFilter(String id, UiFilterOptionsValuesConfig defaultValue) { + this.id = id; + this.defaultValue = defaultValue; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public UiFilterOptionsValuesConfig getDefaultValue() { + return defaultValue; + } + + public void setDefaultValue(UiFilterOptionsValuesConfig defaultValue) { + this.defaultValue = defaultValue; + } +} diff --git a/src/test/resources/filters/AggregationSuggestionEntity_getIndexDocumentJson_expected.json b/src/test/resources/filters/AggregationSuggestionEntity_getIndexDocumentJson_expected.json new file mode 100644 index 0000000..53e9ec9 --- /dev/null +++ b/src/test/resources/filters/AggregationSuggestionEntity_getIndexDocumentJson_expected.json @@ -0,0 +1 @@ +"filterList":[{"filterId":"1"},{"filterId":"2"},{"filterId":"7"},{"filterId":"8"}] \ No newline at end of file diff --git a/src/test/resources/filters/aaiui_filters.json b/src/test/resources/filters/aaiui_filters.json new file mode 100644 index 0000000..31716ed --- /dev/null +++ b/src/test/resources/filters/aaiui_filters.json @@ -0,0 +1,88 @@ +{ + "filters": [ + { + "filterId": "1", + "filterName": "Orchestration-Status", + "displayName": "Orchestration Status", + "dataType": "list", + "dataSource": { + "indexName": "aggregate_generic-vnf_index", + "docType": "default", + "fieldName": "orchestration-status" + } + }, + { + "filterId": "2", + "filterName": "Prov-Status", + "displayName": "Provisioning Status", + "dataType": "list", + "dataSource": { + "indexName": "aggregate_generic-vnf_index", + "docType": "default", + "fieldName": "prov-status" + } + }, + { + "filterId": "3", + "filterName": "Severity", + "displayName": "Severity", + "dataType": "list", + "dataSource": { + "indexName": "di-violations", + "docType": "default", + "fieldName": "severity" + } + }, + { + "filterId": "4", + "filterName": "Category", + "displayName": "Category", + "dataType": "list", + "dataSource": { + "indexName": "di-violations", + "docType": "default", + "fieldName": "category" + } + }, + { + "filterId": "5", + "filterName": "Date", + "displayName": "Date", + "dataType": "date" + }, + { + "filterId": "6", + "filterName": "EntityType", + "displayName": "Object Type", + "dataType": "list", + "dataSource": { + "indexName": "di-violations", + "docType": "default", + "fieldName": "entityType" + } + }, + { + "filterId": "7", + "filterName": "NF-Type", + "displayName": "Network Function Type", + "dataType": "list", + "dataSource": { + "indexName": "aggregate_generic-vnf_index", + "docType": "default", + "fieldName": "nf-type" + } + }, + { + "filterId": "8", + "filterName": "NF-Role", + "displayName": "Network Function Role", + "dataType": "list", + "dataSource": { + "indexName": "aggregate_generic-vnf_index", + "docType": "default", + "fieldName": "nf-role" + } + } + + ] +} \ No newline at end of file diff --git a/src/test/resources/filters/aaiui_views.json b/src/test/resources/filters/aaiui_views.json new file mode 100644 index 0000000..e6ece9f --- /dev/null +++ b/src/test/resources/filters/aaiui_views.json @@ -0,0 +1,38 @@ +{ + "views": [ + { + "viewName" : "vnfSearch", + "filters" : [ + { + "filterId": "1" + }, + { + "filterId": "2" + }, + { + "filterId": "7" + }, + { + "filterId": "8" + } + ] + }, + { + "viewName" : "dataIntegrity", + "filters" : [ + { + "filterId": "3" + }, + { + "filterId": "4" + }, + { + "filterId": "5" + }, + { + "filterId": "6" + } + ] + } + ] +} \ No newline at end of file diff --git a/src/test/resources/filters/filterAggregationEndpoint_emptyRequestBody_expectedResponse.json b/src/test/resources/filters/filterAggregationEndpoint_emptyRequestBody_expectedResponse.json new file mode 100644 index 0000000..95a2b16 --- /dev/null +++ b/src/test/resources/filters/filterAggregationEndpoint_emptyRequestBody_expectedResponse.json @@ -0,0 +1 @@ +{"count":0} \ No newline at end of file diff --git a/src/test/resources/filters/filterAggregationEndpoint_emptyRequestFilterArray_expectedResponse.json b/src/test/resources/filters/filterAggregationEndpoint_emptyRequestFilterArray_expectedResponse.json new file mode 100644 index 0000000..36ae0a5 --- /dev/null +++ b/src/test/resources/filters/filterAggregationEndpoint_emptyRequestFilterArray_expectedResponse.json @@ -0,0 +1 @@ +{"groupby_aggregation":[{"totalChartHits":0,"buckets":[]}]} \ No newline at end of file diff --git a/src/test/resources/filters/filterAggregationEndpoint_emptyRequestFilterArray_requestBody.json b/src/test/resources/filters/filterAggregationEndpoint_emptyRequestFilterArray_requestBody.json new file mode 100644 index 0000000..ba7d987 --- /dev/null +++ b/src/test/resources/filters/filterAggregationEndpoint_emptyRequestFilterArray_requestBody.json @@ -0,0 +1,3 @@ +{ + "filters": [] +} \ No newline at end of file diff --git a/src/test/resources/filters/filterAggregationEndpoint_successPath_expectedResponse.json b/src/test/resources/filters/filterAggregationEndpoint_successPath_expectedResponse.json new file mode 100644 index 0000000..e2c5766 --- /dev/null +++ b/src/test/resources/filters/filterAggregationEndpoint_successPath_expectedResponse.json @@ -0,0 +1 @@ +{"total":116,"aggregations":{"prov-status":[{"doc_count":77,"key":""},{"doc_count":2,"key":"PREPROV"}],"orchestration-status":[{"doc_count":116,"key":"Created"}]}} diff --git a/src/test/resources/filters/filterAggregationEndpoint_successPath_operationResult.json b/src/test/resources/filters/filterAggregationEndpoint_successPath_operationResult.json new file mode 100644 index 0000000..753a11f --- /dev/null +++ b/src/test/resources/filters/filterAggregationEndpoint_successPath_operationResult.json @@ -0,0 +1 @@ +{"took":39,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":116,"max_score":0.0,"hits":[]},"aggregations":{"prov-status":{"doc_count_error_upper_bound":0,"sum_other_doc_count":0,"buckets":[{"key":"","doc_count":77},{"key":"PREPROV","doc_count":2}]},"orchestration-status":{"doc_count_error_upper_bound":0,"sum_other_doc_count":0,"buckets":[{"key":"Created","doc_count":116}]}}} \ No newline at end of file diff --git a/src/test/resources/filters/filterAggregationEndpoint_successPath_requestBody.json b/src/test/resources/filters/filterAggregationEndpoint_successPath_requestBody.json new file mode 100644 index 0000000..c321760 --- /dev/null +++ b/src/test/resources/filters/filterAggregationEndpoint_successPath_requestBody.json @@ -0,0 +1,11 @@ +{ + "filters": [ + { + "filterId": "1", + "filterValue": "Created" + }, + { + "filterId": "2" + } + ] +} \ No newline at end of file -- cgit 1.2.3-korg