DynamoDBSSHRecordStoreFactory implements SSHRecordStoreFactory { @Override public SSHRecordStore create(PrivateKeyStore keyStore) { final String tableName = System.getProperty(ZTSConsts.ZTS_PROP_SSH_DYNAMODB_TABLE_NAME); if (tableName == null || tableName.isEmpty()) { LOGGER.error("SSH Store DynamoDB table name not specified"); throw new ResourceException(ResourceException.SERVICE_UNAVAILABLE, "DynamoDB ssh table name not specified"); } ZTSClientNotificationSenderImpl ztsClientNotificationSender = new ZTSClientNotificationSenderImpl(); AmazonDynamoDB client = getDynamoDBClient(ztsClientNotificationSender, keyStore); return new DynamoDBSSHRecordStore(client, tableName, ztsClientNotificationSender); }  @Override SSHRecordStore create(PrivateKeyStore keyStore);  }
@Test public void testCreate() { System.setProperty(ZTSConsts.ZTS_PROP_SSH_DYNAMODB_TABLE_NAME, "Athenz-ZTS-Table"); PrivateKeyStore keyStore = Mockito.mock(PrivateKeyStore.class); TestDynamoDBSSHRecordStoreFactory factory = new TestDynamoDBSSHRecordStoreFactory(); SSHRecordStore store = factory.create(keyStore); assertNotNull(store); }
@Test public void testCreateAmzClient() { System.setProperty(ZTSConsts.ZTS_PROP_SSH_DYNAMODB_TABLE_NAME, "Athenz-ZTS-Table"); PrivateKeyStore keyStore = Mockito.mock(PrivateKeyStore.class); TestDynamoDBSSHRecordStoreFactory factory = new TestDynamoDBSSHRecordStoreFactory(); try { factory.create(keyStore); } catch (Exception ignored) { } }
@Test public void testCreateMissingTableName() { PrivateKeyStore keyStore = Mockito.mock(PrivateKeyStore.class); System.clearProperty(ZTSConsts.ZTS_PROP_SSH_DYNAMODB_TABLE_NAME); TestDynamoDBSSHRecordStoreFactory factory = new TestDynamoDBSSHRecordStoreFactory(); try { factory.create(keyStore); fail(); } catch (ResourceException ex) { assertEquals(ex.getCode(), ResourceException.SERVICE_UNAVAILABLE); } System.setProperty(ZTSConsts.ZTS_PROP_SSH_DYNAMODB_TABLE_NAME, ""); try { factory.create(keyStore); fail(); } catch (ResourceException ex) { assertEquals(ex.getCode(), ResourceException.SERVICE_UNAVAILABLE); } System.clearProperty(ZTSConsts.ZTS_PROP_SSH_DYNAMODB_TABLE_NAME); }