summaryrefslogtreecommitdiffstats
path: root/auth/auth-cmd/src/test/java/org/onap/aaf/auth/cmd/test/ns/JU_List.java
blob: e4100a021e8296df9f5db73829b69a711fe733f2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*
 * ============LICENSE_START==========================================
 * ===================================================================
 * Copyright © 2018 AT&T Intellectual Property. All rights reserved.
 * ===================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============LICENSE_END============================================
 */

package org.onap.aaf.auth.cmd.test.ns;

import static org.junit.Assert.*;

import java.io.Writer;
import java.net.URI;
import java.util.ArrayList;

import org.onap.aaf.auth.cmd.ns.List;
import org.onap.aaf.auth.cmd.ns.NS;
import org.onap.aaf.auth.env.AuthzEnv;
import org.onap.aaf.cadi.CadiException;
import org.onap.aaf.cadi.Locator;
import org.onap.aaf.cadi.LocatorException;
import org.onap.aaf.cadi.PropAccess;
import org.onap.aaf.cadi.SecuritySetter;
import org.onap.aaf.cadi.client.Future;
import org.onap.aaf.cadi.config.SecurityInfoC;
import org.onap.aaf.cadi.http.HMangr;
import org.onap.aaf.misc.env.APIException;

import aaf.v2_0.Nss;
import aaf.v2_0.Roles;
import aaf.v2_0.Users.User;
import junit.framework.Assert;

import org.onap.aaf.auth.cmd.AAFcli;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.Mockito;
import static org.mockito.Mockito.*;

import org.junit.Test;

public class JU_List {
    
    List list;
    AAFcli aafcli;
    User user;
    
    private class NssStub extends Nss {
        public void addNs(Nss.Ns ns) {    
            if (this.ns == null) {
                this.ns = new ArrayList<>();
            }
            this.ns.add(ns);
        }
        
        private class NsStub extends Ns{
            public void addAttrib(Nss.Ns.Attrib attrib) {
                if ( this.attrib == null) {
                    this.attrib = new ArrayList<>();
                }
                this.attrib.add(attrib);
            }
            
            public void addResponsible(String str) {
                if (this.responsible == null) {
                    this.responsible = new ArrayList<>();
                }
                this.responsible.add(str);
            }
            
            public void addAdmin(String str) {
                if (this.admin == null) {
                    this.admin = new ArrayList<>();
                }
                this.admin.add(str);
            }
        }
        
        
        
        
    }
    

    @Before
    public void setUp() throws APIException, LocatorException, CadiException {
        PropAccess prop = new PropAccess();
        AuthzEnv aEnv = new AuthzEnv();
        Writer wtr = mock(Writer.class);
        Locator loc = mock(Locator.class);
        HMangr hman = new HMangr(aEnv, loc);        
        aafcli = new AAFcli(prop, aEnv, wtr, hman, null, null);
        user = new User();
        NS ns = new NS(aafcli);
        
        list = new List(ns);
    }
    
    @Test
    public void testReport() throws Exception {
        Future<Nss> fu = mock(Future.class);
        NssStub nssStub = new NssStub();
        NssStub.NsStub nsStub = nssStub.new NsStub();
        Nss.Ns.Attrib attrib = mock(Nss.Ns.Attrib.class);
        when(attrib.getKey()).thenReturn("key");
        when(attrib.getValue()).thenReturn("value");
        nsStub.addAttrib(attrib);
        nsStub.addResponsible("test");
        nsStub.addAdmin("admin");
        nssStub.addNs(nsStub);
        fu.value = nssStub;
        aafcli.eval("DETAILS @[ 123");
        
        list.report(fu, "test");
    }
    
    @Test
    public void testGetType() {
        Assert.assertEquals("n/a", list.getType(user));
        user.setType(1);
        Assert.assertEquals("U/P", list.getType(user));
        user.setType(2);
        Assert.assertEquals("U/P2", list.getType(user));
        user.setType(10);
        Assert.assertEquals("FQI", list.getType(user));
        user.setType(200);
        Assert.assertEquals("x509", list.getType(user));
    }
    
}