2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020 Samsung. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.so.adapters.vevnfm.service;
23 import static org.junit.Assert.assertEquals;
24 import static org.onap.so.adapters.vevnfm.service.SubscribeSender.SLASH;
25 import static org.springframework.http.HttpHeaders.CONTENT_TYPE;
26 import static org.springframework.test.web.client.ExpectedCount.once;
27 import static org.springframework.test.web.client.match.MockRestRequestMatchers.content;
28 import static org.springframework.test.web.client.match.MockRestRequestMatchers.header;
29 import static org.springframework.test.web.client.match.MockRestRequestMatchers.method;
30 import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo;
31 import static org.springframework.test.web.client.response.MockRestResponseCreators.withStatus;
32 import org.hamcrest.CoreMatchers;
33 import org.junit.Before;
34 import org.junit.Test;
35 import org.junit.runner.RunWith;
36 import org.onap.aai.domain.yang.EsrSystemInfo;
37 import org.onap.so.adapters.etsisol003adapter.lcm.extclients.vnfm.model.LccnSubscriptionRequest;
38 import org.onap.so.adapters.vevnfm.configuration.ConfigProperties;
39 import org.onap.so.adapters.vevnfm.configuration.StartupConfiguration;
40 import org.onap.so.adapters.vevnfm.exception.VeVnfmException;
41 import org.springframework.beans.factory.annotation.Autowired;
42 import org.springframework.boot.test.context.SpringBootTest;
43 import org.springframework.http.HttpMethod;
44 import org.springframework.http.HttpStatus;
45 import org.springframework.http.MediaType;
46 import org.springframework.test.context.ActiveProfiles;
47 import org.springframework.test.context.junit4.SpringRunner;
48 import org.springframework.test.web.client.MockRestServiceServer;
49 import org.springframework.web.client.RestTemplate;
50 import com.google.gson.Gson;
51 import com.google.gson.GsonBuilder;
54 @RunWith(SpringRunner.class)
55 @ActiveProfiles(StartupConfiguration.TEST_PROFILE)
56 public class SubscribeSenderTest {
58 private static final String URL = "lh";
59 private static final String ID = "1a2s3d4f";
60 private static final String JSON = "{\"id\":\"" + ID + "\"}";
62 private static final Gson GSON;
65 final GsonBuilder builder = new GsonBuilder();
66 builder.serializeNulls();
67 GSON = builder.create();
71 private ConfigProperties configProperties;
74 private SubscribeSender sender;
77 private RestTemplate restTemplate;
79 private String vnfmSubscription;
80 private MockRestServiceServer mockRestServer;
84 vnfmSubscription = configProperties.getVnfmSubscription();
85 mockRestServer = MockRestServiceServer.bindTo(restTemplate).build();
89 public void testSuccess() throws VeVnfmException {
91 final EsrSystemInfo info = new EsrSystemInfo();
92 info.setServiceUrl(URL);
93 final LccnSubscriptionRequest request = new LccnSubscriptionRequest();
95 mockRestServer.expect(once(), requestTo(SLASH + info.getServiceUrl() + vnfmSubscription))
96 .andExpect(header(CONTENT_TYPE, CoreMatchers.containsString(MediaType.APPLICATION_JSON_VALUE)))
97 .andExpect(method(HttpMethod.POST)).andExpect(content().json(GSON.toJson(request)))
98 .andRespond(withStatus(HttpStatus.CREATED).body(JSON).contentType(MediaType.APPLICATION_JSON));
101 final String id = sender.send(info, request);
104 mockRestServer.verify();
105 assertEquals(ID, id);