/*- * ============LICENSE_START======================================================= * Simulator * ================================================================================ * Copyright (C) 2019 Nokia. 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========================================================= */ package org.onap.integration.simulators.nfsimulator.vesclient.rest; import static org.assertj.core.api.Java6Assertions.assertThat; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.onap.integration.simulators.nfsimulator.vesclient.rest.TemplateController.CANNOT_OVERRIDE_TEMPLATE_MSG; import static org.onap.integration.simulators.nfsimulator.vesclient.rest.TemplateController.TEMPLATE_NOT_FOUND_MSG; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import static org.mockito.Mockito.times; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonObject; import com.google.gson.reflect.TypeToken; import java.lang.reflect.Type; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Optional; import org.assertj.core.util.Lists; import org.bson.Document; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.onap.integration.simulators.nfsimulator.vesclient.template.search.IllegalJsonValueException; import org.onap.integration.simulators.nfsimulator.vesclient.db.Storage; import org.onap.integration.simulators.nfsimulator.vesclient.rest.model.SearchExp; import org.onap.integration.simulators.nfsimulator.vesclient.template.Template; import org.springframework.http.MediaType; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MvcResult; import org.springframework.test.web.servlet.setup.MockMvcBuilders; class TemplateControllerTest { private static final String LIST_URL = "/template/list"; private static final String GET_FORMAT_STR = "/template/get/%s"; private static final String SEARCH_ENDPOINT = "/template/search"; private static final String UPLOAD_URL_NOFORCE = "/template/upload"; private static final String UPLOAD_URL_FORCE = "/template/upload?override=true"; private static final String SAMPLE_TEMPLATE_JSON = "{\"event\": {\n" + " \"commonEventHeader\": {\n" + " \"domain\": \"measurementsForVfScaling\",\n" + " \"eventName\": \"vFirewallBroadcastPackets\",\n" + " }" + "}}"; public static final String TEMPLATE_REQUEST = "{\n" + " \"name\": \"someTemplate\",\n" + " \"template\": {\n" + " \"commonEventHeader\": {\n" + " \"domain\": \"notification\",\n" + " \"eventName\": \"vFirewallBroadcastPackets\"\n" + " },\n" + " \"notificationFields\": {\n" + " \"arrayOfNamedHashMap\": [{\n" + " \"name\": \"A20161221.1031-1041.bin.gz\",\n" + "\n" + " \"hashMap\": {\n" + " \"fileformatType\": \"org.3GPP.32.435#measCollec\"\n" + " }\n" + " }]\n" + " }\n" + " }\n" + "}"; private static final Document SAMPLE_TEMPLATE_BSON = Document.parse(SAMPLE_TEMPLATE_JSON); private static final List SAMPLE_TEMPLATE_NAME_LIST = Lists.newArrayList("notification.json", "registration.json"); private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); private static final Gson GSON_OBJ = new GsonBuilder().create(); private MockMvc mockMvc; @Mock private Storage