Search in sources :

Example 1 with FilesHelper

use of com.yahoo.athenz.common.server.util.FilesHelper in project athenz by yahoo.

the class ZMSFileChangeLogStoreCommonTest method testSetFilePermissionsException.

@Test
public void testSetFilePermissionsException() throws IOException {
    ZMSFileChangeLogStoreCommon fstore = new ZMSFileChangeLogStoreCommon(FSTORE_PATH);
    FilesHelper helper = Mockito.mock(FilesHelper.class);
    Mockito.when(helper.setPosixFilePermissions(any(), any())).thenThrow(new IOException("io exception"));
    fstore.filesHelper = helper;
    try {
        File file = new File(FSTORE_PATH, "domain");
        Set<PosixFilePermission> perms = EnumSet.of(PosixFilePermission.OWNER_READ, PosixFilePermission.OWNER_WRITE, PosixFilePermission.OWNER_EXECUTE);
        fstore.setupFilePermissions(file, perms);
        fail();
    } catch (Exception ex) {
        assertTrue(true);
    }
}
Also used : IOException(java.io.IOException) FilesHelper(com.yahoo.athenz.common.server.util.FilesHelper) PosixFilePermission(java.nio.file.attribute.PosixFilePermission) File(java.io.File) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) Test(org.testng.annotations.Test)

Example 2 with FilesHelper

use of com.yahoo.athenz.common.server.util.FilesHelper in project athenz by yahoo.

the class ZMSFileChangeLogStoreCommonTest method testPutException.

@Test
public void testPutException() throws IOException {
    ZMSFileChangeLogStoreCommon fstore = new ZMSFileChangeLogStoreCommon(FSTORE_PATH);
    FilesHelper helper = Mockito.mock(FilesHelper.class);
    Mockito.when(helper.write(any(), any())).thenThrow(new IOException("io exception"));
    fstore.filesHelper = helper;
    Struct data = new Struct();
    data.put("key", "val1");
    try {
        fstore.put("test1", JSON.bytes(data));
        fail();
    } catch (Exception ex) {
        assertTrue(true);
    }
}
Also used : IOException(java.io.IOException) FilesHelper(com.yahoo.athenz.common.server.util.FilesHelper) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) Struct(com.yahoo.rdl.Struct) Test(org.testng.annotations.Test)

Example 3 with FilesHelper

use of com.yahoo.athenz.common.server.util.FilesHelper in project athenz by yahoo.

the class ZMSFileChangeLogStoreCommonTest method testSetupDomainFileException.

@Test
public void testSetupDomainFileException() throws IOException {
    ZMSFileChangeLogStoreCommon fstore = new ZMSFileChangeLogStoreCommon(FSTORE_PATH);
    FilesHelper helper = Mockito.mock(FilesHelper.class);
    Mockito.doThrow(new IOException("io exception")).when(helper).createEmptyFile(any());
    fstore.filesHelper = helper;
    try {
        File file = new File(FSTORE_PATH, "domain");
        fstore.setupDomainFile(file);
        fail();
    } catch (Exception ex) {
        assertTrue(true);
    }
}
Also used : IOException(java.io.IOException) FilesHelper(com.yahoo.athenz.common.server.util.FilesHelper) File(java.io.File) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) Test(org.testng.annotations.Test)

Example 4 with FilesHelper

use of com.yahoo.athenz.common.server.util.FilesHelper in project athenz by yahoo.

the class ZMSFileChangeLogStoreCommonTest method testDeleteException.

@Test
public void testDeleteException() throws IOException {
    ZMSFileChangeLogStoreCommon fstore = new ZMSFileChangeLogStoreCommon(FSTORE_PATH);
    // create the file
    Struct data = new Struct();
    data.put("key", "val1");
    fstore.put("test1", JSON.bytes(data));
    // update the helper to be our mock
    FilesHelper helper = Mockito.mock(FilesHelper.class);
    Mockito.doThrow(new IOException("io exception")).when(helper).delete(any());
    fstore.filesHelper = helper;
    try {
        fstore.delete("test1");
        fail();
    } catch (Exception ex) {
        assertTrue(true);
    }
}
Also used : IOException(java.io.IOException) FilesHelper(com.yahoo.athenz.common.server.util.FilesHelper) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) Struct(com.yahoo.rdl.Struct) Test(org.testng.annotations.Test)

Aggregations

FilesHelper (com.yahoo.athenz.common.server.util.FilesHelper)4 FileNotFoundException (java.io.FileNotFoundException)4 IOException (java.io.IOException)4 Test (org.testng.annotations.Test)4 Struct (com.yahoo.rdl.Struct)2 File (java.io.File)2 PosixFilePermission (java.nio.file.attribute.PosixFilePermission)1