X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=cadi%2Faaf%2Fsrc%2Ftest%2Fjava%2Forg%2Fonap%2Faaf%2Fcadi%2Fpersist%2Ftest%2FJU_PersistFile.java;h=797496a7f8d17e4542ddcf5dcaa73cfe57e9a999;hb=deb396a3d53a84b2eb5a46d40122b4902d72c601;hp=cbe865ebdff2d70299bea070d8e2af2f2d380530;hpb=ceda6e8bc270202bcb24340b86617110289c902e;p=aaf%2Fauthz.git diff --git a/cadi/aaf/src/test/java/org/onap/aaf/cadi/persist/test/JU_PersistFile.java b/cadi/aaf/src/test/java/org/onap/aaf/cadi/persist/test/JU_PersistFile.java index cbe865eb..797496a7 100644 --- a/cadi/aaf/src/test/java/org/onap/aaf/cadi/persist/test/JU_PersistFile.java +++ b/cadi/aaf/src/test/java/org/onap/aaf/cadi/persist/test/JU_PersistFile.java @@ -43,7 +43,7 @@ import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.onap.aaf.cadi.CadiException; import org.onap.aaf.cadi.PropAccess; -import org.onap.aaf.cadi.client.Holder; +import org.onap.aaf.cadi.util.Holder; import org.onap.aaf.cadi.config.Config; import org.onap.aaf.cadi.persist.PersistFile; import org.onap.aaf.misc.env.APIException; @@ -52,70 +52,70 @@ import org.onap.aaf.misc.rosetta.env.RosettaData; public class JU_PersistFile { - private static final String resourceDirString = "src/test/resources"; - private static final String tokenDirString = "tokenDir"; - private static final String tokenFileName = "token"; - - private static final int data = 5; - private static final long expires = 10000; - - private static final byte[] cred = "password".getBytes(); - - private PropAccess access; - private Holder hp = new Holder(null); - private Holder hl = new Holder(null); - - @Mock private RosettaDF dfMock; - @Mock private RosettaData dataMock; - @Mock private Holder hpMock; - - @Before - public void setup() throws APIException { - MockitoAnnotations.initMocks(this); - - when(dfMock.newData()).thenReturn(dataMock); - when(dataMock.load(data)).thenReturn(dataMock); - when(dataMock.load((CipherInputStream)any())).thenReturn(dataMock); - - access = new PropAccess(new PrintStream(new ByteArrayOutputStream()), new String[0]); - access.setProperty(Config.CADI_TOKEN_DIR, resourceDirString); - } - - @After - public void tearDown() { - File dir = new File(resourceDirString + '/' + tokenDirString); - for (File f : dir.listFiles()) { - f.delete(); - } - dir.delete(); - } - - @Test - public void test() throws CadiException, APIException, IOException { - PersistFile persistFile = new PersistFile(access, tokenDirString); - // Second call is for coverage - persistFile = new PersistFile(access, tokenDirString); - Path filepath = persistFile.writeDisk(dfMock, data, cred, tokenFileName, expires); - persistFile.readDisk(dfMock, cred, tokenFileName, hp, hl); - assertThat(persistFile.readExpiration(filepath), is(expires)); - - FileTime ft1 = persistFile.getFileTime(tokenFileName, hp); - FileTime ft2 = persistFile.getFileTime(tokenFileName, hpMock); - assertThat(ft1.toMillis(), is(ft2.toMillis())); - - persistFile.deleteFromDisk(filepath); - persistFile.deleteFromDisk(resourceDirString + '/' + tokenDirString + '/' + tokenFileName); - assertThat(persistFile.readExpiration(filepath), is(0L)); - - persistFile.getPath(resourceDirString + '/' + tokenDirString + '/' + tokenFileName); - - persistFile.writeDisk(dfMock, data, null, tokenFileName, expires); - try { - persistFile.readDisk(dfMock, cred, tokenFileName, hp, hl); - fail("Should've thrown an exception"); - } catch (CadiException e) { - assertThat(e.getMessage(), is(CadiException.class.getName() + ": Hash does not match in Persistence")); - } - } + private static final String resourceDirString = "src/test/resources"; + private static final String tokenDirString = "tokenDir"; + private static final String tokenFileName = "token"; + + private static final int data = 5; + private static final long expires = 10000; + + private static final byte[] cred = "password".getBytes(); + + private PropAccess access; + private Holder hp = new Holder(null); + private Holder hl = new Holder(null); + + @Mock private RosettaDF dfMock; + @Mock private RosettaData dataMock; + @Mock private Holder hpMock; + + @Before + public void setup() throws APIException { + MockitoAnnotations.initMocks(this); + + when(dfMock.newData()).thenReturn(dataMock); + when(dataMock.load(data)).thenReturn(dataMock); + when(dataMock.load((CipherInputStream)any())).thenReturn(dataMock); + + access = new PropAccess(new PrintStream(new ByteArrayOutputStream()), new String[0]); + access.setProperty(Config.CADI_TOKEN_DIR, resourceDirString); + } + + @After + public void tearDown() { + File dir = new File(resourceDirString + '/' + tokenDirString); + for (File f : dir.listFiles()) { + f.delete(); + } + dir.delete(); + } + + @Test + public void test() throws CadiException, APIException, IOException { + PersistFile persistFile = new PersistFile(access, tokenDirString); + // Second call is for coverage + persistFile = new PersistFile(access, tokenDirString); + Path filepath = persistFile.writeDisk(dfMock, data, cred, tokenFileName, expires); + persistFile.readDisk(dfMock, cred, tokenFileName, hp, hl); + assertThat(persistFile.readExpiration(filepath), is(expires)); + + FileTime ft1 = persistFile.getFileTime(tokenFileName, hp); + FileTime ft2 = persistFile.getFileTime(tokenFileName, hpMock); + assertThat(ft1.toMillis(), is(ft2.toMillis())); + + persistFile.deleteFromDisk(filepath); + persistFile.deleteFromDisk(resourceDirString + '/' + tokenDirString + '/' + tokenFileName); + assertThat(persistFile.readExpiration(filepath), is(0L)); + + persistFile.getPath(resourceDirString + '/' + tokenDirString + '/' + tokenFileName); + + persistFile.writeDisk(dfMock, data, null, tokenFileName, expires); + try { + persistFile.readDisk(dfMock, cred, tokenFileName, hp, hl); + fail("Should've thrown an exception"); + } catch (CadiException e) { + assertThat(e.getMessage(), is(CadiException.class.getName() + ": Hash does not match in Persistence")); + } + } }