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