60727b6af1b46409ad0802869a91aea43b7a52e3
[aaf/authz.git] / auth / auth-core / src / test / java / org / onap / aaf / auth / rserv / test / JU_TypedCode.java
1 /*******************************************************************************
2  * ============LICENSE_START====================================================
3  * * org.onap.aaf
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  * *
21  ******************************************************************************/
22
23 package org.onap.aaf.auth.rserv.test;
24
25 import static org.junit.Assert.*;
26
27 import static org.mockito.Mockito.mock;
28 import static org.mockito.Mockito.when;
29 import static org.mockito.Matchers.anyString;
30
31 import java.io.IOException;
32
33 import javax.servlet.ServletException;
34
35 import org.junit.Before;
36 import org.junit.Test;
37 import org.junit.runner.RunWith;
38 import org.mockito.Mock;
39 //import org.onap.aaf.auth.rserv.Acceptor;
40 import org.onap.aaf.auth.rserv.HttpCode;
41 import org.onap.aaf.auth.rserv.HttpMethods;
42 import org.onap.aaf.auth.rserv.RouteReport;
43 import org.onap.aaf.auth.rserv.TypedCode;
44 import org.onap.aaf.misc.env.TimeTaken;
45 import org.onap.aaf.misc.env.Trans;
46 import org.powermock.modules.junit4.PowerMockRunner;
47
48 @RunWith(PowerMockRunner.class)
49 public class JU_TypedCode {
50     TypedCode typedCode;
51     @Mock
52     RouteReport routeReportMock;
53
54     @Before
55     public void setUp(){
56         typedCode = new TypedCode();
57     }
58
59     @Test
60     public void testFirst(){
61         String returnVal = typedCode.first();
62         assertNull(returnVal);
63     }
64
65     @Test
66     public void testAdd() {
67         HttpCode<?, ?> code = mock(HttpCode.class);
68         typedCode.add(code , "test", "test1", "test2");
69     }
70
71     @Test
72     public void testPrep() throws IOException, ServletException, ClassNotFoundException {
73         Trans trans = mock(Trans.class);
74         TimeTaken time = new TimeTaken("yell", 2) {
75             @Override
76             public void output(StringBuilder sb) {
77                 // TODO Auto-generated method stub
78             }
79         };
80         when(trans.start(";na=me;,prop", 8)).thenReturn(time);
81         HttpCode<?, ?> code = mock(HttpCode.class);
82         code.pathParam(null, null);
83         code.isAuthorized(null); //Testing httpcode, currently not working
84         code.no_cache();
85         code.toString();
86
87         typedCode.add(code , "");
88         typedCode.prep(null , "q");
89
90         typedCode.add(code , "t");
91         typedCode.prep(trans , null);
92
93         typedCode.add(code , "t");
94         typedCode.prep(trans , "");
95
96         typedCode.add(code, "POST /authn/validate application/CredRequest+json;charset=utf-8;version=2.0,application/json;version=2.0,*/*");
97         //typedCode.prep(trans , "POST /authn/validate application/CredRequest+json;charset=utf-8;version=2.0,application/json;version=2.0,*/*");
98     }
99
100     @Test
101     public void testRelatedTo() {
102         HttpCode<?, ?> code = mock(HttpCode.class);
103         StringBuilder sb = new StringBuilder();
104         typedCode.relatedTo(code, sb);
105     }
106
107 }