Change all the packages from openecomp to onap
[aai/traversal.git] / aai-traversal / src / test / java / org / onap / aai / retiredcustomer / RetiredConsumerTest.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017 AT&T Intellectual Property. 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
10  *
11  *    http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  *
20  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
21  */
22 package org.onap.aai.retiredcustomer;
23
24 import com.att.eelf.configuration.EELFLogger;
25 import com.att.eelf.configuration.EELFManager;
26 import org.junit.Before;
27 import org.junit.Test;
28 import org.mockito.Mockito;
29 import org.onap.aai.introspection.Version;
30 import org.onap.aai.rest.retired.RetiredConsumer;
31
32 import javax.ws.rs.core.*;
33 import java.util.*;
34
35 import static org.junit.Assert.assertEquals;
36 import static org.junit.Assert.assertNotNull;
37 import static org.mockito.Matchers.anyObject;
38 import static org.mockito.Mockito.when;
39
40 public abstract class RetiredConsumerTest {
41
42     protected static final MediaType APPLICATION_JSON = MediaType.valueOf("application/json");
43
44     private static final Set<Integer> VALID_HTTP_STATUS_CODES = new HashSet<>();
45
46     static {
47         VALID_HTTP_STATUS_CODES.add(200);
48         VALID_HTTP_STATUS_CODES.add(201);
49         VALID_HTTP_STATUS_CODES.add(204);
50     }
51
52     protected RetiredConsumer retiredConsumer;
53     protected HttpHeaders httpHeaders;
54     protected UriInfo uriInfo;
55
56     private MultivaluedMap<String, String> headersMultiMap;
57     private MultivaluedMap<String, String> queryParameters;
58
59     private List<String> aaiRequestContextList;
60
61     private List<MediaType> outputMediaTypes;
62
63     private static final EELFLogger logger = EELFManager.getInstance().getLogger(RetiredConsumer.class.getName());
64
65     @Before
66     public void setup(){
67         logger.info("Starting the setup for the integration tests of Rest Endpoints");
68
69         retiredConsumer     = getRetiredConsumer();
70         httpHeaders         = Mockito.mock(HttpHeaders.class);
71         uriInfo             = Mockito.mock(UriInfo.class);
72
73         headersMultiMap     = new MultivaluedHashMap<>();
74         queryParameters     = Mockito.spy(new MultivaluedHashMap<>());
75
76         headersMultiMap.add("X-FromAppId", "JUNIT");
77         headersMultiMap.add("X-TransactionId", UUID.randomUUID().toString());
78         headersMultiMap.add("Real-Time", "true");
79         headersMultiMap.add("Accept", "application/json");
80         headersMultiMap.add("aai-request-context", "");
81
82         outputMediaTypes = new ArrayList<>();
83         outputMediaTypes.add(APPLICATION_JSON);
84
85         aaiRequestContextList = new ArrayList<>();
86         aaiRequestContextList.add("");
87
88         when(httpHeaders.getAcceptableMediaTypes()).thenReturn(outputMediaTypes);
89         when(httpHeaders.getRequestHeaders()).thenReturn(headersMultiMap);
90
91         when(httpHeaders.getRequestHeader("aai-request-context")).thenReturn(aaiRequestContextList);
92
93
94         when(uriInfo.getQueryParameters()).thenReturn(queryParameters);
95         when(uriInfo.getQueryParameters(false)).thenReturn(queryParameters);
96
97         // TODO - Check if this is valid since RemoveDME2QueryParameters seems to be very unreasonable
98         Mockito.doReturn(null).when(queryParameters).remove(anyObject());
99
100         when(httpHeaders.getMediaType()).thenReturn(APPLICATION_JSON);
101     }
102
103     @Test
104     public void testRetiredForAllEndPoints(){
105         when(uriInfo.getPath()).thenReturn("/aai/v3/cloud-infrastructure/pservers/pserver/test-pserver1");
106
107         Response response = retiredConsumer.createMessageGet(Version.getLatest().toString(), httpHeaders, uriInfo, null);
108         assertNotNull(response);
109         assertEquals(Response.Status.GONE.getStatusCode(), response.getStatus());
110
111         response = retiredConsumer.createMessagePost(Version.getLatest().toString(), httpHeaders, uriInfo, null);
112         assertNotNull(response);
113         assertEquals(Response.Status.GONE.getStatusCode(), response.getStatus());
114
115         response = retiredConsumer.createMessagePatch(Version.getLatest().toString(), httpHeaders, uriInfo, null);
116         assertNotNull(response);
117         assertEquals(Response.Status.GONE.getStatusCode(), response.getStatus());
118
119         response = retiredConsumer.createMessagePut(Version.getLatest().toString(), httpHeaders, uriInfo, null);
120         assertNotNull(response);
121         assertEquals(Response.Status.GONE.getStatusCode(), response.getStatus());
122
123         response = retiredConsumer.createMessageDelete(Version.getLatest().toString(), httpHeaders, uriInfo, null);
124         assertNotNull(response);
125         assertEquals(Response.Status.GONE.getStatusCode(), response.getStatus());
126     }
127
128     public abstract RetiredConsumer getRetiredConsumer();
129 }