public void testListAvailableFormTemplateInfos() throws Exception { String clientAccountId = clientSecurity1.getPublicKeyString(); Vector emptyResponse = server.listAvailableFormTemplateInfos(clientAccountId); assertEquals("Already has forms?", 0, emptyResponse.size()); ServerBulletinStore store = coreServer.getStore(); MartusCrypto security = server.getSecurity(); byte[] fakeTemplateData = new byte[] {1, 2, 3, 4, 5}; String invalidBase64Template = StreamableBase64.encode(fakeTemplateData); try { ServerForClients.saveBase64FormTemplate( store, clientAccountId, invalidBase64Template, security, logger); fail("Should have thrown saving invalid template"); } catch (FormTemplateParsingException ignoreExpected) { } createAndSaveSampleTemplate(store, clientAccountId, "First", security); createAndSaveSampleTemplate(store, clientAccountId, "Second", security); Vector storedTemplates = store.getListOfFormTemplatesForAccount(clientAccountId); assertEquals(2, storedTemplates.size()); TemplateInfoForMirroring storedInfo1 = new TemplateInfoForMirroring((File) storedTemplates.get(0)); TemplateInfoForMirroring storedInfo2 = new TemplateInfoForMirroring((File) storedTemplates.get(1)); Vector resultVector = server.listAvailableFormTemplateInfos(clientAccountId); assertEquals("Wrong count?", 2, resultVector.size()); TemplateInfoForMirroring gotInfo1 = new TemplateInfoForMirroring((String) resultVector.get(0)); TemplateInfoForMirroring gotInfo2 = new TemplateInfoForMirroring((String) resultVector.get(1)); assertEquals(storedInfo1, gotInfo1); assertEquals(storedInfo2, gotInfo2); assertTrue("Wrong order?", gotInfo1.asString().compareTo(gotInfo2.asString()) < 0); }
public void createAndSaveSampleTemplate( ServerBulletinStore store, String clientAccountId, String title, MartusCrypto security) throws Exception { FormTemplate template = createSampleTemplate(title); String base64Template = template.getExportedTemplateAsBase64String(security); ServerForClients.saveBase64FormTemplate( store, clientAccountId, base64Template, security, logger); }