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