Search in sources :

Example 51 with Struct

use of com.yahoo.rdl.Struct 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)

Example 52 with Struct

use of com.yahoo.rdl.Struct in project athenz by yahoo.

the class ZMSFileChangeLogStoreCommonTest method testGetNonExistent.

@Test
public void testGetNonExistent() {
    ZMSFileChangeLogStoreCommon fstore = new ZMSFileChangeLogStoreCommon(FSTORE_PATH);
    Struct st = fstore.get("NotExistent", Struct.class);
    assertNull(st);
}
Also used : Struct(com.yahoo.rdl.Struct) Test(org.testng.annotations.Test)

Example 53 with Struct

use of com.yahoo.rdl.Struct in project athenz by yahoo.

the class ZMSFileChangeLogStoreCommonTest method testGetExistent.

@Test
public void testGetExistent() {
    ZMSFileChangeLogStoreCommon fstore = new ZMSFileChangeLogStoreCommon(FSTORE_PATH);
    Struct data = new Struct();
    data.put("key", "val1");
    fstore.put("test1", JSON.bytes(data));
    Struct st = fstore.get("test1", Struct.class);
    assertNotNull(st);
    assertEquals(st.get("key"), "val1");
}
Also used : Struct(com.yahoo.rdl.Struct) Test(org.testng.annotations.Test)

Example 54 with Struct

use of com.yahoo.rdl.Struct in project athenz by yahoo.

the class ZMSFileChangeLogStoreCommonTest method testJsonValueAsBytes.

@Test
public void testJsonValueAsBytes() {
    ZMSFileChangeLogStoreCommon fstore = new ZMSFileChangeLogStoreCommon(FSTORE_PATH);
    ObjectMapper mapper = Mockito.mock(ObjectMapper.class);
    Mockito.when(mapper.writerWithView(Struct.class)).thenThrow(new RuntimeException("invalid class"));
    fstore.jsonMapper = mapper;
    Struct testStruct = new Struct();
    testStruct.putIfAbsent("key", "value");
    assertNull(fstore.jsonValueAsBytes(testStruct, Struct.class));
}
Also used : ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Struct(com.yahoo.rdl.Struct) Test(org.testng.annotations.Test)

Example 55 with Struct

use of com.yahoo.rdl.Struct in project athenz by yahoo.

the class ZMSFileChangeLogStoreCommonTest method testGetJsonException.

@Test
public void testGetJsonException() throws IOException {
    ZMSFileChangeLogStoreCommon fstore = new ZMSFileChangeLogStoreCommon(FSTORE_PATH);
    Struct data = new Struct();
    data.put("key", "val1");
    fstore.put("test1", JSON.bytes(data));
    ObjectMapper mapper = Mockito.mock(ObjectMapper.class);
    File file = new File(FSTORE_PATH, "test1");
    Mockito.when(mapper.readValue(file, Struct.class)).thenThrow(new RuntimeException("invalid class"));
    fstore.jsonMapper = mapper;
    assertNull(fstore.get("test1", Struct.class));
}
Also used : File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Struct(com.yahoo.rdl.Struct) Test(org.testng.annotations.Test)

Aggregations

Struct (com.yahoo.rdl.Struct)61 Test (org.testng.annotations.Test)30 Array (com.yahoo.rdl.Array)10 ZMSFileChangeLogStore (com.yahoo.athenz.zts.store.impl.ZMSFileChangeLogStore)7 AuthzDetailsEntity (com.yahoo.athenz.common.config.AuthzDetailsEntity)5 Path (java.nio.file.Path)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 Assertion (com.yahoo.athenz.zms.Assertion)3 Policy (com.yahoo.athenz.zms.Policy)3 ZpeMatch (com.yahoo.athenz.zpe.match.ZpeMatch)3 File (java.io.File)3 AuthzDetailsField (com.yahoo.athenz.common.config.AuthzDetailsField)2 FilesHelper (com.yahoo.athenz.common.server.util.FilesHelper)2 PublicKeyEntry (com.yahoo.athenz.zms.PublicKeyEntry)2 ServiceIdentity (com.yahoo.athenz.zms.ServiceIdentity)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 BasicSessionCredentials (com.amazonaws.auth.BasicSessionCredentials)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 AthenzConfig (com.yahoo.athenz.common.config.AthenzConfig)1