use of com.structurizr.encryption.AesEncryptionStrategy in project java by structurizr.
the class EncryptedJsonTests method test_write_and_read.
@Test
public void test_write_and_read() throws Exception {
final Workspace workspace1 = new Workspace("Name", "Description");
// output the model as JSON
EncryptedJsonWriter jsonWriter = new EncryptedJsonWriter(true);
AesEncryptionStrategy encryptionStrategy = new AesEncryptionStrategy("password");
final EncryptedWorkspace encryptedWorkspace1 = new EncryptedWorkspace(workspace1, encryptionStrategy);
StringWriter stringWriter = new StringWriter();
jsonWriter.write(encryptedWorkspace1, stringWriter);
// and read it back again
EncryptedJsonReader jsonReader = new EncryptedJsonReader();
StringReader stringReader = new StringReader(stringWriter.toString());
final EncryptedWorkspace encryptedWorkspace2 = jsonReader.read(stringReader);
assertEquals("Name", encryptedWorkspace2.getName());
assertEquals("Description", encryptedWorkspace2.getDescription());
encryptedWorkspace2.getEncryptionStrategy().setPassphrase(encryptionStrategy.getPassphrase());
final Workspace workspace2 = encryptedWorkspace2.getWorkspace();
assertEquals("Name", workspace2.getName());
assertEquals("Description", workspace2.getDescription());
}
use of com.structurizr.encryption.AesEncryptionStrategy in project java by structurizr.
the class EncryptedJsonWriterTests method test_write_ThrowsAnIllegalArgumentException_WhenANullWriterIsSpecified.
@Test
public void test_write_ThrowsAnIllegalArgumentException_WhenANullWriterIsSpecified() throws Exception {
try {
EncryptedJsonWriter writer = new EncryptedJsonWriter(true);
Workspace workspace = new Workspace("Name", "Description");
EncryptedWorkspace encryptedWorkspace = new EncryptedWorkspace(workspace, new AesEncryptionStrategy("password"));
writer.write(encryptedWorkspace, null);
fail();
} catch (IllegalArgumentException e) {
assertEquals("Writer cannot be null.", e.getMessage());
}
}
use of com.structurizr.encryption.AesEncryptionStrategy in project java by structurizr.
the class StructurizrClientIntegrationTests method test_putAndGetWorkspace_WithEncryption.
@Test
public void test_putAndGetWorkspace_WithEncryption() throws Exception {
structurizrClient.setEncryptionStrategy(new AesEncryptionStrategy("password"));
Workspace workspace = new Workspace("Structurizr client library tests - with encryption", "A test workspace for the Structurizr client library");
SoftwareSystem softwareSystem = workspace.getModel().addSoftwareSystem("Software System", "Description");
Person person = workspace.getModel().addPerson("Person", "Description");
person.uses(softwareSystem, "Uses");
SystemContextView systemContextView = workspace.getViews().createSystemContextView(softwareSystem, "SystemContext", "Description");
systemContextView.addAllElements();
structurizrClient.putWorkspace(20081, workspace);
workspace = structurizrClient.getWorkspace(20081);
assertNotNull(workspace.getModel().getSoftwareSystemWithName("Software System"));
assertNotNull(workspace.getModel().getPersonWithName("Person"));
assertEquals(1, workspace.getModel().getRelationships().size());
assertEquals(1, workspace.getViews().getSystemContextViews().size());
// and check the archive version is readable
EncryptedWorkspace archivedWorkspace = new EncryptedJsonReader().read(new FileReader(getArchivedWorkspace()));
assertEquals(20081, archivedWorkspace.getId());
assertEquals("Structurizr client library tests - with encryption", archivedWorkspace.getName());
assertTrue(archivedWorkspace.getEncryptionStrategy() instanceof AesEncryptionStrategy);
assertEquals(1, workspaceArchiveLocation.listFiles().length);
}
Aggregations