2 * ============LICENSE_START====================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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====================================================
22 package org.onap.aaf.auth.layer.test;
24 import static org.junit.Assert.*;
26 import org.junit.Before;
27 import org.junit.Test;
28 import org.mockito.Mock;
29 import static org.mockito.Mockito.*;
31 import java.lang.reflect.Method;
32 import java.util.ArrayList;
33 import java.util.Collection;
34 import java.util.HashSet;
35 import java.util.List;
38 import javax.servlet.ServletRequest;
40 import org.onap.aaf.auth.env.AuthzTrans;
41 import org.onap.aaf.auth.layer.Result;
43 import junit.framework.Assert;
45 public class JU_Result {
50 String details = "details";
53 @SuppressWarnings({ "unchecked", "rawtypes" })
56 //result = mock(Result.class);
61 public void testOk() {
63 Collection col = new ArrayList();
64 List list = mock(List.class);
65 Set set = mock(Set.class);
66 Integer[] R = new Integer[1];
68 Assert.assertNotNull(Result.ok());
69 Assert.assertNotNull(Result.ok(value));
70 Assert.assertNotNull(Result.ok(col));
71 Assert.assertNotNull(Result.ok(list));
72 Assert.assertNotNull(Result.ok(set));
73 Assert.assertNotNull(Result.ok(R));
75 Collection<String> col1 = new ArrayList();
76 List<String> list1 = new ArrayList();
77 Set<String> set1 = new HashSet<>();
78 Integer[] R1 = new Integer[0];
83 Assert.assertNotNull(Result.ok(col1));
84 Assert.assertNotNull(Result.ok(list1));
85 Assert.assertNotNull(Result.ok(set1));
86 Assert.assertNotNull(Result.ok(R1));
90 public void testErr() {
91 Result result = Result.create(null, 0, null, null);
93 Exception e = mock(Exception.class);
95 Assert.assertNotNull(result.err(r)); //Result case
96 Assert.assertNotNull(result.err(e)); //Exception case
97 Assert.assertNotNull(result.err(0, "test", "test")); //Multiple case
102 public void testCreate() {
103 Result result = Result.create(null, 0, null, null);
104 Assert.assertNotNull(Result.create(null, 0, null, null));
105 Assert.assertNotNull(Result.create(null, 0, null, "arg"));
106 Assert.assertNotNull(result.create(0, result));
110 public void testOks() {
111 Result result = Result.create(null, 0, null, null);
113 Assert.assertNotNull(result.isOK());
114 Assert.assertNotNull(result.notOK());
115 Assert.assertNotNull(result.isOKhasData());
116 Assert.assertNotNull(result.notOKorIsEmpty());
118 Result result1 = Result.create(null, 5, "test", "test");
119 Assert.assertNotNull(result1.emptyList(true));
120 Assert.assertNotNull(result1.isOK());
121 Assert.assertNotNull(result1.notOK());
122 Assert.assertNotNull(result1.isOKhasData());
123 Assert.assertNotNull(result1.notOKorIsEmpty());
125 Result result2 = Result.create(null, 0, "test", "test");
126 Assert.assertNotNull(result2.emptyList(false));
127 Assert.assertNotNull(result2.isOKhasData());
128 Assert.assertNotNull(result2.notOKorIsEmpty());
132 public void testEmptyList() {
133 Result result = Result.create(null, 0, null, null);
135 Assert.assertNotNull(result.emptyList(true));
136 Assert.assertNotNull(result.emptyList(false));
137 Assert.assertFalse(result.isEmpty());
141 public void testPartialContent() {
142 Result result = Result.create(null, 0, null, null);
144 Assert.assertNotNull(result.partialContent(true));
145 Assert.assertNotNull(result.partialContent(false));
146 Assert.assertFalse(result.partialContent());
148 Result result1 = Result.create(null, 1, "test", null);
149 Assert.assertNotNull(result1.partialContent(true));
150 Assert.assertNotNull(result1.partialContent());
154 public void testToString() {
155 Result result = Result.create(null, 0, null, null);
157 Assert.assertNull(result.toString() );
159 Result result1 = Result.create(null, 5, "test", "test");
161 Assert.assertNotNull(result1.toString());
164 Result result2 = Result.create(value , 5, "test", "test");
166 Assert.assertNotNull(result2.toString());
170 public void testErrorString() {
171 Result result = Result.create(null, 0, "test", "test");
172 Assert.assertEquals("Error - test", result.errorString());
173 Result result1 = Result.create(null, 1, "test", "test");
174 Assert.assertEquals("Security - test",result1.errorString());
175 Result result2 = Result.create(null, 2, "test", "test");
176 Assert.assertEquals("Denied - test",result2.errorString());
177 Result result3 = Result.create(null, 3, "test", "test");
178 Assert.assertEquals("Policy - test",result3.errorString());
179 Result result4 = Result.create(null, 4, "test", "test");
180 Assert.assertEquals("BadData - test",result4.errorString());
181 Result result5 = Result.create(null, 5, "test", "test");
182 Assert.assertEquals("NotImplemented - test",result5.errorString());
183 Result result6 = Result.create(null, 6, "test", "test");
184 Assert.assertEquals("NotFound - test",result6.errorString());
185 Result result7 = Result.create(null, 7, "test", "test");
186 Assert.assertEquals("AlreadyExists - test",result7.errorString());
187 Result result8 = Result.create(null, 8, "test", "test");
188 Assert.assertEquals("ActionNotComplete - test",result8.errorString());