diff options
-rw-r--r-- | auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/update/Upload.java | 106 | ||||
-rw-r--r-- | misc/env/src/main/java/org/onap/aaf/misc/env/Slot.java | 2 | ||||
-rw-r--r-- | misc/env/src/test/java/org/onap/aaf/misc/env/JU_StoreImplTest.java (renamed from misc/env/src/test/java/org/onap/aaf/misc/env/jaxb/JU_StoreImplTest.java) | 0 | ||||
-rw-r--r-- | misc/env/src/test/java/org/onap/aaf/misc/env/impl/JU_AbsTrans.java | 292 | ||||
-rw-r--r-- | misc/env/src/test/java/org/onap/aaf/misc/env/impl/JU_AbsTransJaxb.java | 177 |
5 files changed, 525 insertions, 52 deletions
diff --git a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/update/Upload.java b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/update/Upload.java index 76472b5f..87bdf272 100644 --- a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/update/Upload.java +++ b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/update/Upload.java @@ -3,6 +3,8 @@ * org.onap.aaf * =========================================================================== * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved. + * + * Modifications Copyright (C) 2018 IBM. * =========================================================================== * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -37,6 +39,59 @@ import org.onap.aaf.misc.env.TimeTaken; import com.datastax.driver.core.ResultSet; public class Upload extends Batch { + + private static final int BATCH_LENGTH = 100; + + int count; + int batchCnt; + + // APPROVALS + private static final String APPR_INS_FMT=" INSERT INTO authz.approval " + + "(id,approver,last_notified,memo,operation,status,ticket,type,user) " + + "VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s);\n"; + private static final Boolean[] APPR_QUOTES = new Boolean[]{false,true,true,true,true,true,false,true,true}; + + // ARTIFACTS + private static final String ARTI_INS_FMT=" INSERT INTO authz.artifact " + + "(mechid,machine,ca,dir,expires,notify,ns,os_user,renewdays,sans,sponsor,type) " + + "VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s);\n"; + private static final Boolean[] ARTI_QUOTES = new Boolean[] + {true,true,true,true,true,true,true,true,false,false,true,false}; + + // CREDS + private static final String CRED_INS_FMT=" INSERT INTO authz.cred " + + "(id,type,expires,cred,notes,ns,other,prev) " + + "VALUES (%s,%s,%s,%s,%s,%s,%s,%s);\n"; + private static final Boolean[] CRED_QUOTES = new Boolean[] + {true,false,true,false,true,true,false,false}; + + // NS + private static final String NS_INS_FMT=" INSERT INTO authz.ns " + + "(name,description,parent,scope,type) " + + "VALUES (%s,%s,%s,%s,%s);\n"; + private static final Boolean[] NS_QUOTES = new Boolean[] + {true,true,true,false,false}; + + // x509 + private static final String X509_INS_FMT=" INSERT INTO authz.x509 " + + "(ca,serial,id,x500,x509) " + + "VALUES (%s,%s,%s,%s,%s);\n"; + private static final Boolean[] X509_QUOTES = new Boolean[] + {true,false,true,true,true}; + + // ROLE + private static final String ROLE_INS_FMT=" INSERT INTO authz.role " + + "(ns,name,description,perms) " + + "VALUES (%s,%s,%s,%s);\n"; + private static final Boolean[] ROLE_QUOTES = new Boolean[] + {true,true,true,false}; + // ROLE + private static final String PERM_INS_FMT=" INSERT INTO authz.perm " + + "(ns,type,instance,action,description,roles) " + + "VALUES (%s,%s,%s,%s,%s,%s);\n"; + private static final Boolean[] PERM_QUOTES = new Boolean[] + {true,true,true,true,true,false}; + public Upload(AuthzTrans trans) throws APIException, IOException, OrganizationException { super(trans.env()); trans.info().log("Starting Connection Process"); @@ -55,10 +110,6 @@ public class Upload extends Batch { } } - private static final int BATCH_LENGTH = 100; - - int count,batchCnt; - @Override protected void run(AuthzTrans trans) { String line; @@ -144,53 +195,6 @@ public class Upload extends Batch { } - // APPROVALS - private static final String APPR_INS_FMT=" INSERT INTO authz.approval " - + "(id,approver,last_notified,memo,operation,status,ticket,type,user) " - + "VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s);\n"; - private static final Boolean[] APPR_QUOTES = new Boolean[]{false,true,true,true,true,true,false,true,true}; - - // ARTIFACTS - private static final String ARTI_INS_FMT=" INSERT INTO authz.artifact " - + "(mechid,machine,ca,dir,expires,notify,ns,os_user,renewdays,sans,sponsor,type) " - + "VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s);\n"; - private static final Boolean[] ARTI_QUOTES = new Boolean[] - {true,true,true,true,true,true,true,true,false,false,true,false}; - - // CREDS - private static final String CRED_INS_FMT=" INSERT INTO authz.cred " - + "(id,type,expires,cred,notes,ns,other,prev) " - + "VALUES (%s,%s,%s,%s,%s,%s,%s,%s);\n"; - private static final Boolean[] CRED_QUOTES = new Boolean[] - {true,false,true,false,true,true,false,false}; - - // NS - private static final String NS_INS_FMT=" INSERT INTO authz.ns " - + "(name,description,parent,scope,type) " - + "VALUES (%s,%s,%s,%s,%s);\n"; - private static final Boolean[] NS_QUOTES = new Boolean[] - {true,true,true,false,false}; - - // x509 - private static final String X509_INS_FMT=" INSERT INTO authz.x509 " - + "(ca,serial,id,x500,x509) " - + "VALUES (%s,%s,%s,%s,%s);\n"; - private static final Boolean[] X509_QUOTES = new Boolean[] - {true,false,true,true,true}; - - // ROLE - private static final String ROLE_INS_FMT=" INSERT INTO authz.role " - + "(ns,name,description,perms) " - + "VALUES (%s,%s,%s,%s);\n"; - private static final Boolean[] ROLE_QUOTES = new Boolean[] - {true,true,true,false}; - // ROLE - private static final String PERM_INS_FMT=" INSERT INTO authz.perm " - + "(ns,type,instance,action,description,roles) " - + "VALUES (%s,%s,%s,%s,%s,%s);\n"; - private static final Boolean[] PERM_QUOTES = new Boolean[] - {true,true,true,true,true,false}; - private String build(String feed, List<String> array) { String rv; diff --git a/misc/env/src/main/java/org/onap/aaf/misc/env/Slot.java b/misc/env/src/main/java/org/onap/aaf/misc/env/Slot.java index 33a65752..95954ec8 100644 --- a/misc/env/src/main/java/org/onap/aaf/misc/env/Slot.java +++ b/misc/env/src/main/java/org/onap/aaf/misc/env/Slot.java @@ -59,7 +59,7 @@ public final class Slot { * @param name
* The name of the Slot's key.
*/
- Slot(int index, String name) {
+ public Slot(int index, String name) {
slot = index;
key = name;
}
diff --git a/misc/env/src/test/java/org/onap/aaf/misc/env/jaxb/JU_StoreImplTest.java b/misc/env/src/test/java/org/onap/aaf/misc/env/JU_StoreImplTest.java index db48345c..db48345c 100644 --- a/misc/env/src/test/java/org/onap/aaf/misc/env/jaxb/JU_StoreImplTest.java +++ b/misc/env/src/test/java/org/onap/aaf/misc/env/JU_StoreImplTest.java diff --git a/misc/env/src/test/java/org/onap/aaf/misc/env/impl/JU_AbsTrans.java b/misc/env/src/test/java/org/onap/aaf/misc/env/impl/JU_AbsTrans.java new file mode 100644 index 00000000..572941f3 --- /dev/null +++ b/misc/env/src/test/java/org/onap/aaf/misc/env/impl/JU_AbsTrans.java @@ -0,0 +1,292 @@ +/** + * ============LICENSE_START==================================================== + * org.onap.aaf + * =========================================================================== + * Copyright (c) 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.misc.env.impl; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.mockito.MockitoAnnotations.initMocks; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.onap.aaf.misc.env.Decryptor; +import org.onap.aaf.misc.env.Encryptor; +import org.onap.aaf.misc.env.Env; +import org.onap.aaf.misc.env.LogTarget; +import org.onap.aaf.misc.env.Slot; +import org.onap.aaf.misc.env.StaticSlot; +import org.onap.aaf.misc.env.StoreImpl; +import org.onap.aaf.misc.env.TimeTaken; + +public class JU_AbsTrans { + + @Mock + Env delegate; + + @Mock + BasicEnv delegate1; + + @Mock + LogTarget lt; + + @Before + public void setUp() { + initMocks(this); + } + + class AbsTransImpl extends AbsTrans{ + + public AbsTransImpl(Env delegate) { + super(delegate); + // TODO Auto-generated constructor stub + } + + public AbsTransImpl(BasicEnv delegate) { + super(delegate); + // TODO Auto-generated constructor stub + } + + @Override + public Slot slot(String name) { + // TODO Auto-generated method stub + return new Slot(-1, "test"); + } + + @Override + public <T> T get(StaticSlot slot, T dflt) { + // TODO Auto-generated method stub + return null; + } + + @Override + public String setProperty(String tag, String value) { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getProperty(String tag) { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getProperty(String tag, String deflt) { + // TODO Auto-generated method stub + return null; + } + + @Override + public Decryptor decryptor() { + // TODO Auto-generated method stub + return null; + } + + @Override + public Encryptor encryptor() { + // TODO Auto-generated method stub + return null; + } + + @Override + protected TimeTaken newTimeTaken(String name, int flag) { + // TODO Auto-generated method stub + return new TimeTaken("nameTest", Env.XML) { + + @Override + public void output(StringBuilder sb) { + // TODO Auto-generated method stub + + } + }; + } + + } + + @Test + public void testFatal() { + AbsTransImpl absTransObj = new AbsTransImpl(delegate); + Mockito.doReturn(lt).when(delegate).fatal(); + LogTarget lt = absTransObj.fatal(); + assertTrue(lt instanceof LogTarget); + } + + @Test + public void testError() { + AbsTransImpl absTransObj = new AbsTransImpl(delegate); + Mockito.doReturn(lt).when(delegate).error(); + LogTarget lt = absTransObj.error(); + assertTrue(lt instanceof LogTarget); + } + + @Test + public void testAudit() { + AbsTransImpl absTransObj = new AbsTransImpl(delegate); + Mockito.doReturn(lt).when(delegate).audit(); + LogTarget lt = absTransObj.audit(); + assertTrue(lt instanceof LogTarget); + } + + @Test + public void testInit() { + AbsTransImpl absTransObj = new AbsTransImpl(delegate); + Mockito.doReturn(lt).when(delegate).init(); + LogTarget lt = absTransObj.init(); + assertTrue(lt instanceof LogTarget); + } + + @Test + public void testWarn() { + AbsTransImpl absTransObj = new AbsTransImpl(delegate); + Mockito.doReturn(lt).when(delegate).warn(); + LogTarget lt = absTransObj.warn(); + assertTrue(lt instanceof LogTarget); + } + + @Test + public void testInfo() { + AbsTransImpl absTransObj = new AbsTransImpl(delegate); + Mockito.doReturn(lt).when(delegate).info(); + LogTarget lt = absTransObj.info(); + assertTrue(lt instanceof LogTarget); + } + + @Test + public void testDebug() { + AbsTransImpl absTransObj = new AbsTransImpl(delegate); + Mockito.doReturn(lt).when(delegate).debug(); + LogTarget lt = absTransObj.debug(); + assertTrue(lt instanceof LogTarget); + } + + @Test + public void testTrace() { + AbsTransImpl absTransObj = new AbsTransImpl(delegate); + Mockito.doReturn(lt).when(delegate).trace(); + LogTarget lt = absTransObj.trace(); + assertTrue(lt instanceof LogTarget); + } + + @Test + public void testStart() { + AbsTransImpl absTransObj = new AbsTransImpl(delegate); + TimeTaken lt = absTransObj.start("test",1); + assertEquals("nameTest", lt.name); + } + + @Test + public void testCheckpint() { + AbsTransImpl absTransObj = new AbsTransImpl(delegate); + absTransObj.checkpoint("test"); + assertEquals("nameTest", ((TimeTaken)absTransObj.trail.get(0)).name); + } + + @Test + public void testCheckpintAddFlag() { + AbsTransImpl absTransObj = new AbsTransImpl(delegate); + absTransObj.checkpoint("test",1); + assertEquals("nameTest", ((TimeTaken)absTransObj.trail.get(0)).name); + } + + @Test + public void testAuditTrailWithEmptyTrail() { + AbsTransImpl absTransObj = new AbsTransImpl(delegate); + Mockito.doReturn(lt).when(delegate).info(); + Mockito.doReturn(true).when(lt).isLoggable(); + absTransObj.auditTrail(1, new StringBuilder(), 1); + //assertEquals("nameTest", ((TimeTaken)absTransObj.trail.get(0)).name); + } + + @Test + public void testAuditTrail() { + AbsTransImpl absTransObj = new AbsTransImpl(delegate); + Mockito.doReturn(lt).when(delegate).info(); + Mockito.doReturn(true).when(lt).isLoggable(); + TimeTaken tt=absTransObj.newTimeTaken("test", 1); + absTransObj.trail.add(tt); + absTransObj.trail.add(tt); + absTransObj.trail.add(tt); + absTransObj.auditTrail(1, new StringBuilder(), 2); + //assertEquals("nameTest", ((TimeTaken)absTransObj.trail.get(0)).name); + } + + @Test + public void testAuditTrailLoggableFalse() { + AbsTransImpl absTransObj = new AbsTransImpl(delegate); + Mockito.doReturn(lt).when(delegate).info(); + Mockito.doReturn(false).when(lt).isLoggable(); + TimeTaken tt=absTransObj.newTimeTaken("test", 1); + absTransObj.trail.add(tt); + absTransObj.trail.add(tt); + absTransObj.trail.add(tt); + absTransObj.auditTrail(1, new StringBuilder(), 1); + //assertEquals("nameTest", ((TimeTaken)absTransObj.trail.get(0)).name); + } + + @Test + public void testAuditTrailNullSB() { + AbsTransImpl absTransObj = new AbsTransImpl(delegate); + Mockito.doReturn(lt).when(delegate).info(); + Mockito.doReturn(true).when(lt).isLoggable(); + TimeTaken tt=absTransObj.newTimeTaken("test", 1); + absTransObj.trail.add(tt); + absTransObj.trail.add(tt); + absTransObj.trail.add(tt); + absTransObj.auditTrail(1, null, 1); + //assertEquals("nameTest", ((TimeTaken)absTransObj.trail.get(0)).name); + } + + @Test + public void testAuditTrailEmpptyFlag() { + AbsTransImpl absTransObj = new AbsTransImpl(delegate); + Mockito.doReturn(lt).when(delegate).info(); + Mockito.doReturn(true).when(lt).isLoggable(); + TimeTaken tt=absTransObj.newTimeTaken("test", 1); + absTransObj.trail.add(tt); + absTransObj.trail.add(tt); + absTransObj.trail.add(tt); + absTransObj.auditTrail(1, null, new int[] {}); + //assertEquals("nameTest", ((TimeTaken)absTransObj.trail.get(0)).name); + } + + @Test + public void testPut() { + AbsTransImpl absTransObj = new AbsTransImpl(delegate1); + try { + absTransObj.put(absTransObj.slot("test"), "test"); + } catch(Exception e){ + assertTrue(e instanceof NullPointerException); + } + } + + @Test + public void testGet() { + AbsTransImpl absTransObj = new AbsTransImpl(delegate1); + try { + absTransObj.get(absTransObj.slot("test"), "test"); + } catch(Exception e){ + e.printStackTrace(); + assertTrue(e instanceof NullPointerException); + } + } +}
\ No newline at end of file diff --git a/misc/env/src/test/java/org/onap/aaf/misc/env/impl/JU_AbsTransJaxb.java b/misc/env/src/test/java/org/onap/aaf/misc/env/impl/JU_AbsTransJaxb.java new file mode 100644 index 00000000..98848804 --- /dev/null +++ b/misc/env/src/test/java/org/onap/aaf/misc/env/impl/JU_AbsTransJaxb.java @@ -0,0 +1,177 @@ +/** + * ============LICENSE_START==================================================== + * org.onap.aaf + * =========================================================================== + * Copyright (c) 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.misc.env.impl; + +import static org.mockito.MockitoAnnotations.initMocks; + +import javax.xml.namespace.QName; +import javax.xml.validation.Schema; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.onap.aaf.misc.env.APIException; +import org.onap.aaf.misc.env.DataFactory; +import org.onap.aaf.misc.env.Decryptor; +import org.onap.aaf.misc.env.Encryptor; +import org.onap.aaf.misc.env.EnvJAXB; +import org.onap.aaf.misc.env.LogTarget; +import org.onap.aaf.misc.env.Slot; +import org.onap.aaf.misc.env.StaticSlot; +import org.onap.aaf.misc.env.TimeTaken; + +public class JU_AbsTransJaxb { + + @Mock + EnvJAXB delegate; + + @Mock + LogTarget lt; + + @Before + public void setUp() { + initMocks(this); + } + + class AbsTransJAXBImpl extends AbsTransJAXB{ + + public AbsTransJAXBImpl(EnvJAXB env) { + super(env); + // TODO Auto-generated constructor stub + } + + @Override + public String setProperty(String tag, String value) { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getProperty(String tag) { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getProperty(String tag, String deflt) { + // TODO Auto-generated method stub + return null; + } + + @Override + public Decryptor decryptor() { + // TODO Auto-generated method stub + return null; + } + + @Override + public Encryptor encryptor() { + // TODO Auto-generated method stub + return null; + } + + @Override + public Slot slot(String name) { + // TODO Auto-generated method stub + return null; + } + + @Override + public <T> T get(StaticSlot slot, T dflt) { + // TODO Auto-generated method stub + return null; + } + + @Override + protected TimeTaken newTimeTaken(String name, int flag) { + // TODO Auto-generated method stub + return null; + } + + + } + + + @Test + public void testNewDataFactory() { + AbsTransJAXB absTransObj = new AbsTransJAXBImpl(delegate); + DataFactory<Object> lt = null; + + try { + Mockito.doReturn(lt).when(delegate).newDataFactory(new Class[] {AbsTransJAXB.class}); + lt = absTransObj.newDataFactory(new Class[] {AbsTransJAXB.class}); + } catch (APIException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + //assertTrue(lt instanceof LogTarget); + } + + @Test + public void testNewDataFactorySchema() { + AbsTransJAXB absTransObj = new AbsTransJAXBImpl(delegate); + DataFactory<Object> lt = null; + Schema schema = Mockito.mock(Schema.class); + try { + Mockito.doReturn(lt).when(delegate).newDataFactory(schema, new Class[] {AbsTransJAXB.class}); + lt = absTransObj.newDataFactory(schema, new Class[] {AbsTransJAXB.class}); + } catch (APIException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + //assertTrue(lt instanceof LogTarget); + } + + @Test + public void testNewDataFactoryQname() { + AbsTransJAXB absTransObj = new AbsTransJAXBImpl(delegate); + DataFactory<Object> lt = null; + QName schema = Mockito.mock(QName.class); + try { + Mockito.doReturn(lt).when(delegate).newDataFactory(schema, new Class[] {AbsTransJAXB.class}); + lt = absTransObj.newDataFactory(schema, new Class[] {AbsTransJAXB.class}); + } catch (APIException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + //assertTrue(lt instanceof LogTarget); + } + + @Test + public void testNewDataFactorySchemaQname() { + AbsTransJAXB absTransObj = new AbsTransJAXBImpl(delegate); + DataFactory<Object> lt = null; + QName qname = Mockito.mock(QName.class); + Schema schema = Mockito.mock(Schema.class); + try { + Mockito.doReturn(lt).when(delegate).newDataFactory(schema, qname,new Class[] {AbsTransJAXB.class}); + lt = absTransObj.newDataFactory(schema, qname,new Class[] {AbsTransJAXB.class}); + } catch (APIException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + //assertTrue(lt instanceof LogTarget); + } + + +}
\ No newline at end of file |