2 * ============LICENSE_START====================================================
\r
4 * ===========================================================================
\r
5 * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
\r
6 * ===========================================================================
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
18 * ============LICENSE_END====================================================
\r
21 package org.onap.aaf.misc.env;
\r
23 import static org.junit.Assert.assertEquals;
\r
24 import static org.mockito.Mockito.when;
\r
26 import org.junit.Before;
\r
27 import org.junit.Test;
\r
28 import org.junit.runner.RunWith;
\r
29 import org.mockito.Mock;
\r
30 import org.mockito.runners.MockitoJUnitRunner;
\r
31 import org.onap.aaf.misc.env.impl.BasicTrans;
\r
33 @RunWith(MockitoJUnitRunner.class)
\r
34 public class JU_BasicTransTest {
\r
36 BasicTrans trans = null;
\r
39 private EnvJAXB env;
\r
42 private TimeTaken timeTaken;
\r
45 public void setUp() throws Exception {
\r
46 trans = new BasicTrans(env);
\r
50 public void testSlot() {
\r
51 Slot slot = new Slot(1, "XML");
\r
52 when(env.slot("XML")).thenReturn(slot);
\r
54 Slot outputSlot = trans.slot("XML");
\r
55 Object[] state = new Object[2];
\r
57 slot.put(state, "JSON");
\r
59 assertEquals(slot.get(state), "JSON");
\r
60 assertEquals(slot.getKey(), outputSlot.getKey());
\r
61 assertEquals(slot.toString(), outputSlot.toString());
\r
65 public void testGetStaticSlot() {
\r
66 StaticSlot staticSlot = new StaticSlot(1, "XML");
\r
67 when(env.get(staticSlot)).thenReturn(staticSlot.toString());
\r
69 assertEquals(staticSlot.toString(), trans.get(staticSlot));
\r
73 public void testGetStaticSlotWithT() {
\r
74 StaticSlot staticSlot = new StaticSlot(1, "XML");
\r
75 when(env.get(staticSlot, "XML")).thenReturn(staticSlot.getKey());
\r
77 assertEquals(staticSlot.getKey(), trans.get(staticSlot, "XML"));
\r
81 public void testSetProperty() {
\r
83 String value = "value";
\r
84 String defltValue = "diffValue";
\r
85 when(env.setProperty(tag, value)).thenReturn(value);
\r
86 when(env.getProperty(tag)).thenReturn(value);
\r
87 when(env.getProperty(tag, defltValue)).thenReturn(defltValue);
\r
89 assertEquals(value, trans.setProperty(tag, value));
\r
90 assertEquals(value, trans.getProperty(tag));
\r
91 assertEquals(defltValue, trans.getProperty(tag, defltValue));
\r
95 public void testDecryptor() {
\r
96 when(env.decryptor()).thenReturn(Decryptor.NULL);
\r
98 assertEquals(Decryptor.NULL, trans.decryptor());
\r
99 assertEquals("tag", trans.decryptor().decrypt("tag"));
\r
103 public void testEncryptor() {
\r
104 when(env.encryptor()).thenReturn(Encryptor.NULL);
\r
106 assertEquals(Encryptor.NULL, trans.encryptor());
\r
107 assertEquals("tag", trans.encryptor().encrypt("tag"));
\r