d303755fbf6f698d32f7743071189885d161b077
[aaf/authz.git] / auth / auth-oauth / src / test / java / org / onap / aaf / auth / oauth / mapper / JU_MapperIntrospect1_0Test.java
1 /**
2  * ============LICENSE_START====================================================
3  * org.onap.aaf
4  * ===========================================================================
5  * Copyright (c) 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  */
21 package org.onap.aaf.auth.oauth.mapper;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.mockito.MockitoAnnotations.initMocks;
25
26 import java.util.HashSet;
27
28 import javax.servlet.http.HttpServletRequest;
29 import javax.xml.ws.handler.MessageContext.Scope;
30
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.mockito.Mock;
34 import org.onap.aaf.auth.dao.cass.OAuthTokenDAO.Data;
35 import org.onap.aaf.auth.layer.Result;
36
37 import aafoauth.v2_0.Introspect;
38
39 public class JU_MapperIntrospect1_0Test {
40         @Mock
41         private HttpServletRequest req;
42
43         Data data;
44
45         @Before
46         public void setup() {
47                 initMocks(this);
48                 data = new Data();
49         }
50
51         @Test
52         public void testIntrospect() {
53                 data.type = 1;
54
55                 Result<Data> dataResult = Result.create(data, 0, "detail", "var");
56
57                 MapperIntrospect<Introspect> mapper = new MapperIntrospect1_0();
58
59                 Result<Introspect> intro = mapper.introspect(dataResult);
60
61                 assertEquals(intro.value.getClientType(), "confidential");
62         }
63
64         @Test
65         public void testIntrospectWithUnknowType() {
66                 data.type = 5;
67                 data.scopes = new HashSet<String>();
68
69                 data.scopes.add(Scope.APPLICATION.toString());
70                 data.scopes.add(Scope.HANDLER.toString());
71
72                 Result<Data> dataResult = Result.create(data, 0, "detail", "var");
73
74                 MapperIntrospect<Introspect> mapper = new MapperIntrospect1_0();
75
76                 Result<Introspect> intro = mapper.introspect(dataResult);
77
78                 assertEquals(intro.value.getClientType(), "unknown");
79         }
80
81         @Test
82         public void testIntrospectWithNotOk() {
83                 data.type = 5;
84
85                 Result<Data> dataResult = Result.create(data, 1, "detail", "var");
86
87                 MapperIntrospect<Introspect> mapper = new MapperIntrospect1_0();
88
89                 Result<Introspect> intro = mapper.introspect(dataResult);
90
91                 assertEquals(intro.value, null);
92         }
93
94 }