From 54c248980b3d790d2aa5fa3def9e8ca9e29c54ef Mon Sep 17 00:00:00 2001 From: anhefti Date: Mon, 15 Jun 2020 12:43:31 +0200 Subject: [PATCH] mor integration tests --- .../converter/ArrayOfStringConverter.java | 2 +- .../impl/converter/InlineTableConverter.java | 2 +- .../integration/UseCasesIntegrationTest.java | 86 ++++++++++++++++++- 3 files changed, 85 insertions(+), 5 deletions(-) diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/converter/ArrayOfStringConverter.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/converter/ArrayOfStringConverter.java index 10b26c9a..4971c76d 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/converter/ArrayOfStringConverter.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/converter/ArrayOfStringConverter.java @@ -85,7 +85,7 @@ public class ArrayOfStringConverter implements AttributeValueConverter { final ConfigurationValue value, final boolean xml) throws IOException { - final String val = (value.value != null) ? value.value : attribute.getDefaultValue(); + final String val = (value != null && value.value != null) ? value.value : attribute.getDefaultValue(); if (StringUtils.isNotBlank(val)) { final String[] values = StringUtils.split(val, Constants.LIST_SEPARATOR); diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/converter/InlineTableConverter.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/converter/InlineTableConverter.java index 34c860e1..f005df9b 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/converter/InlineTableConverter.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/converter/InlineTableConverter.java @@ -92,7 +92,7 @@ public class InlineTableConverter implements AttributeValueConverter { (xml) ? XML_KEY_TEMPLATE : JSON_KEY_TEMPLATE, AttributeValueConverter.extractName(attribute)))); - if (StringUtils.isBlank(value.value)) { + if (value == null || StringUtils.isBlank(value.value)) { out.write((xml) ? XML_EMPTY_ARRAY : JSON_EMPTY_ARRAY); out.flush(); return; diff --git a/src/test/java/ch/ethz/seb/sebserver/gui/integration/UseCasesIntegrationTest.java b/src/test/java/ch/ethz/seb/sebserver/gui/integration/UseCasesIntegrationTest.java index d0b35fdf..83812f60 100644 --- a/src/test/java/ch/ethz/seb/sebserver/gui/integration/UseCasesIntegrationTest.java +++ b/src/test/java/ch/ethz/seb/sebserver/gui/integration/UseCasesIntegrationTest.java @@ -60,6 +60,7 @@ import ch.ethz.seb.sebserver.gbl.model.institution.LmsSetup; import ch.ethz.seb.sebserver.gbl.model.institution.LmsSetup.LmsType; import ch.ethz.seb.sebserver.gbl.model.institution.LmsSetupTestResult; import ch.ethz.seb.sebserver.gbl.model.sebconfig.ConfigCreationInfo; +import ch.ethz.seb.sebserver.gbl.model.sebconfig.ConfigKey; import ch.ethz.seb.sebserver.gbl.model.sebconfig.Configuration; import ch.ethz.seb.sebserver.gbl.model.sebconfig.ConfigurationAttribute; import ch.ethz.seb.sebserver.gbl.model.sebconfig.ConfigurationNode; @@ -82,6 +83,7 @@ import ch.ethz.seb.sebserver.gui.service.examconfig.impl.ExamConfigurationServic import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.RestCallError; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.RestServiceImpl; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.exam.CheckExamConsistency; +import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.exam.DeleteExamConfigMapping; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.exam.ExportExamConfig; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.exam.GetExam; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.exam.GetExamConfigMappingNames; @@ -118,6 +120,7 @@ import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.clientconfig. import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.clientconfig.SaveClientConfig; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.examconfig.AttachDefaultOrientation; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.examconfig.CopyConfiguration; +import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.examconfig.ExportConfigKey; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.examconfig.ExportPlainXML; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.examconfig.GetConfigAttributes; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.examconfig.GetConfigurationPage; @@ -1838,17 +1841,25 @@ public class UseCasesIntegrationTest extends GuiIntegrationTest { // - Get Exam // - Get List of available Exam Config for mapping // - Map a Exam Config to the Exam + // - Remove Exam Config + // - Add config again + // - Export Config Key + // - Export Config as XML public void testUsecase16_MapExamConfigToExam() throws IOException { final RestServiceImpl restService = createRestServiceForUser( "examAdmin2", "examAdmin2", new GetExamPage(), + new GetExamConfigNode(), new GetExamConfigNodeNames(), new GetExamConfigMappingNames(), new GetExamConfigMappingsPage(), new SaveExamConfigMapping(), new NewExamConfigMapping(), - new CheckExamConsistency()); + new CheckExamConsistency(), + new DeleteExamConfigMapping(), + new ExportConfigKey(), + new ExportExamConfig()); // get exam final Result> exams = restService @@ -1902,7 +1913,7 @@ public class UseCasesIntegrationTest extends GuiIntegrationTest { assertTrue(mappingsPage.isEmpty()); // create new config node mapping - final Result newExamConfigMap = restService.getBuilder(NewExamConfigMapping.class) + Result newExamConfigMap = restService.getBuilder(NewExamConfigMapping.class) .withFormParam(Domain.EXAM_CONFIGURATION_MAP.ATTR_INSTITUTION_ID, String.valueOf(exam.institutionId)) .withFormParam(Domain.EXAM_CONFIGURATION_MAP.ATTR_EXAM_ID, String.valueOf(exam.id)) .withFormParam(Domain.EXAM_CONFIGURATION_MAP.ATTR_CONFIGURATION_NODE_ID, configName.modelId) @@ -1910,7 +1921,7 @@ public class UseCasesIntegrationTest extends GuiIntegrationTest { assertNotNull(newExamConfigMap); assertFalse(newExamConfigMap.hasError()); - final ExamConfigurationMap examConfigurationMap = newExamConfigMap.get(); + ExamConfigurationMap examConfigurationMap = newExamConfigMap.get(); assertNotNull(examConfigurationMap); assertEquals("New Exam Config", examConfigurationMap.configName); assertEquals(exam.name, examConfigurationMap.examName); @@ -1935,6 +1946,75 @@ public class UseCasesIntegrationTest extends GuiIntegrationTest { .getOr(Collections.emptyList()); assertNotNull(newAlerts); assertTrue(newAlerts.isEmpty()); + + // check the state of exam config is now in "In Use" + Result examConfigCall = restService.getBuilder(GetExamConfigNode.class) + .withURIVariable(API.PARAM_MODEL_ID, configName.modelId) + .call(); + + assertNotNull(examConfigCall); + assertFalse(examConfigCall.hasError()); + ConfigurationNode configurationNode = examConfigCall.get(); + assertEquals(ConfigurationStatus.IN_USE, configurationNode.status); + + // delete the configuration mapping + restService.getBuilder(DeleteExamConfigMapping.class) + .withURIVariable(API.PARAM_MODEL_ID, examConfigurationMap.getModelId()) + .call(); + + // check the state of exam config is now in "Ready To Use" + final Result examConfigCall2 = restService.getBuilder(GetExamConfigNode.class) + .withURIVariable(API.PARAM_MODEL_ID, configName.modelId) + .call(); + + assertNotNull(examConfigCall2); + assertFalse(examConfigCall2.hasError()); + final ConfigurationNode configurationNode2 = examConfigCall2.get(); + assertEquals(ConfigurationStatus.READY_TO_USE, configurationNode2.status); + + // Re-Map the configuration to the exam and check again the state. + newExamConfigMap = restService.getBuilder(NewExamConfigMapping.class) + .withFormParam(Domain.EXAM_CONFIGURATION_MAP.ATTR_INSTITUTION_ID, String.valueOf(exam.institutionId)) + .withFormParam(Domain.EXAM_CONFIGURATION_MAP.ATTR_EXAM_ID, String.valueOf(exam.id)) + .withFormParam(Domain.EXAM_CONFIGURATION_MAP.ATTR_CONFIGURATION_NODE_ID, configName.modelId) + .call(); + + assertNotNull(newExamConfigMap); + assertFalse(newExamConfigMap.hasError()); + examConfigurationMap = newExamConfigMap.get(); + assertNotNull(examConfigurationMap); + assertEquals("New Exam Config", examConfigurationMap.configName); + assertEquals(exam.name, examConfigurationMap.examName); + + examConfigCall = restService.getBuilder(GetExamConfigNode.class) + .withURIVariable(API.PARAM_MODEL_ID, configName.modelId) + .call(); + + assertNotNull(examConfigCall); + assertFalse(examConfigCall.hasError()); + configurationNode = examConfigCall.get(); + assertEquals(ConfigurationStatus.IN_USE, configurationNode.status); + + // export Config Key + final ConfigKey configKey = restService.getBuilder(ExportConfigKey.class) + .withURIVariable(API.PARAM_MODEL_ID, String.valueOf(examConfigurationMap.configurationNodeId)) + .call() + .getOrThrow(); + assertNotNull(configKey); + //assertEquals("e4af6cf8deb9434e69e8dc6c373418712546de35807d8bfbd6bb98790f8d0774", configKey.key); + + // export config to XML + final InputStream input = restService.getBuilder(ExportExamConfig.class) + .withURIVariable(API.PARAM_MODEL_ID, String.valueOf(examConfigurationMap.configurationNodeId)) + .withURIVariable(API.PARAM_PARENT_MODEL_ID, String.valueOf(examConfigurationMap.examId)) + .call() + .getOrThrow(); + + final String xmlString = StreamUtils.copyToString(input, Charsets.UTF_8); + assertNotNull(xmlString); +// assertEquals( +// "allowAudioCaptureallowBrowsingBackForwardallowDictationallowDictionaryLookupallowDisplayMirroringallowDownUploadsallowedDisplayBuiltinallowedDisplaysMaxNumber1allowFlashFullscreenallowiOSBetaVersionNumber0allowiOSVersionNumberMajor9allowiOSVersionNumberMinor3allowiOSVersionNumberPatch5allowPDFPlugInallowPreferencesWindowallowQuitallowScreenSharingallowSiriallowSpellCheckallowSpellCheckDictionaryda-DKen-AUen-GBen-USes-ESfr-FRpt-PTsv-SEsv-FIallowSwitchToApplicationsallowUserAppFolderInstallallowUserSwitchingallowVideoCaptureallowVirtualMachineallowWlanaudioControlEnabledaudioMuteaudioSetVolumeLevelaudioVolumeLevel25blacklistURLFilterblockPopUpWindowsbrowserMessagingPingTime120000browserMessagingSocketws://localhost:8706browserScreenKeyboardbrowserURLSaltbrowserUserAgentbrowserUserAgentiOS0browserUserAgentiOSCustombrowserUserAgentMac0browserUserAgentMacCustombrowserUserAgentWinDesktopMode0browserUserAgentWinDesktopModeCustombrowserUserAgentWinTouchMode0browserUserAgentWinTouchModeCustombrowserUserAgentWinTouchModeIPadMozilla/5.0 (iPad; CPU OS 12_4_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.1.2 Mobile/15E148 Safari/604.1browserViewMode0browserWindowAllowReloadbrowserWindowShowURL0browserWindowTitleSuffixchooseFileToUploadPolicy0createNewDesktopdetectStoppedProcessdownloadAndOpenSebConfigdownloadDirectoryOSXdownloadDirectoryWindownloadPDFFilesenableAltEscenableAltF4enableAltMouseWheelenableAltTabenableAppSwitcherCheckenableBrowserWindowToolbarenableCtrlEscenableDrawingEditorenableEscenableF1enableF10enableF11enableF12enableF2enableF3enableF4enableF5enableF6enableF7enableF8enableF9enableJavaenableJavaScriptenableLoggingenablePlugInsenablePrintScreenenablePrivateClipboardenableRightMouseenableSebBrowserenableStartMenuenableTouchExitenableZoomPageenableZoomTextexamSessionClearCookiesOnEndexamSessionClearCookiesOnStartexitKey12exitKey210exitKey35forceAppFolderInstallhashedAdminPasswordhashedQuitPasswordhideBrowserWindowToolbarhookKeysignoreExitKeysinsideSebEnableChangeAPasswordinsideSebEnableEaseOfAccessinsideSebEnableLockThisComputerinsideSebEnableLogOffinsideSebEnableNetworkConnectionSelectorinsideSebEnableShutDowninsideSebEnableStartTaskManagerinsideSebEnableSwitchUserinsideSebEnableVmWareClientShadekillExplorerShelllockOnMessageSocketCloselogDirectoryOSXlogDirectoryWinlogLevel1mainBrowserWindowHeight100%mainBrowserWindowPositioning1mainBrowserWindowWidth100%minMacOSVersion0mobileAllowPictureInPictureMediaPlaybackmobileAllowQRCodeConfigmobileAllowSingleAppModemobileEnableASAMmobileEnableGuidedAccessLinkTransformmobilePreventAutoLockmobileShowSettingsmobileStatusBarAppearance1mobileStatusBarAppearanceExtended1monitorProcessesnewBrowserWindowAllowReloadnewBrowserWindowByLinkBlockForeignnewBrowserWindowByLinkHeight100%newBrowserWindowByLinkPolicy2newBrowserWindowByLinkPositioning2newBrowserWindowByLinkWidth100%newBrowserWindowByScriptBlockForeignnewBrowserWindowByScriptPolicy2newBrowserWindowNavigationnewBrowserWindowShowReloadWarningnewBrowserWindowShowURL1openDownloadsoriginatorVersionSEB_Server_0.3.0permittedProcessesactiveallowUserToChooseAppargumentsautostartdescriptionexecutablefirefox.exeiconInTaskbaridentifierFirefoxoriginalNamefirefox.exeos1path../xulrunner/runInBackgroundstrongKilltitleSEBpinEmbeddedCertificatesprohibitedProcessesactivecurrentUserdescriptionexecutableRiotidentifieroriginalNameRiotos1strongKilluseractivecurrentUserdescriptionexecutableseamonkeyidentifieroriginalNameseamonkeyos1strongKilluseractivecurrentUserdescriptionexecutableDiscordidentifieroriginalNameDiscordos1strongKilluseractivecurrentUserdescriptionexecutableSlackidentifieroriginalNameSlackos1strongKilluseractivecurrentUserdescriptionexecutableTeamsidentifieroriginalNameTeamsos1strongKilluseractivecurrentUserdescriptionexecutableCamRecorderidentifieroriginalNameCamRecorderos1strongKilluseractivecurrentUserdescriptionexecutablejoin.meidentifieroriginalNamejoin.meos1strongKilluseractivecurrentUserdescriptionexecutableRPCSuiteidentifieroriginalNameRPCSuiteos1strongKilluseractivecurrentUserdescriptionexecutableRPCServiceidentifieroriginalNameRPCServiceos1strongKilluseractivecurrentUserdescriptionexecutableRemotePCDesktopidentifieroriginalNameRemotePCDesktopos1strongKilluseractivecurrentUserdescriptionexecutablebeamyourscreen-hostidentifieroriginalNamebeamyourscreen-hostos1strongKilluseractivecurrentUserdescriptionexecutableAeroAdminidentifieroriginalNameAeroAdminos1strongKilluseractivecurrentUserdescriptionexecutableMikogo-hostidentifieroriginalNameMikogo-hostos1strongKilluseractivecurrentUserdescriptionexecutablechromotingidentifieroriginalNamechromotingos1strongKilluseractivecurrentUserdescriptionexecutablevncserveruiidentifieroriginalNamevncserveruios1strongKilluseractivecurrentUserdescriptionexecutablevncvieweridentifieroriginalNamevncvieweros1strongKilluseractivecurrentUserdescriptionexecutablevncserveridentifieroriginalNamevncserveros1strongKilluseractivecurrentUserdescriptionexecutableTeamVieweridentifieroriginalNameTeamVieweros1strongKilluseractivecurrentUserdescriptionexecutableGotoMeetingWinStoreidentifieroriginalNameGotoMeetingWinStoreos1strongKilluseractivecurrentUserdescriptionexecutableg2mcomm.exeidentifieroriginalNameg2mcomm.exeos1strongKilluseractivecurrentUserdescriptionexecutableSkypeHostidentifieroriginalNameSkypeHostos1strongKilluseractivecurrentUserdescriptionexecutableSkypeidentifieroriginalNameSkypeos1strongKilluserproxiesAutoConfigurationEnabledAutoConfigurationJavaScriptAutoConfigurationURLAutoDiscoveryEnabledExceptionsListExcludeSimpleHostnamesFTPEnableFTPPassiveFTPPasswordFTPPort21FTPProxyFTPRequiresPasswordFTPUsernameHTTPEnableHTTPPasswordHTTPPort80HTTPProxyHTTPRequiresPasswordHTTPSEnableHTTPSPasswordHTTPSPort443HTTPSProxyHTTPSRequiresPasswordHTTPSUsernameHTTPUsernameRTSPEnableRTSPPasswordRTSPPort554RTSPProxyRTSPRequiresPasswordRTSPUsernameSOCKSEnableSOCKSPasswordSOCKSPort1080SOCKSProxySOCKSRequiresPasswordSOCKSUsernameproxySettingsPolicy0quitURLquitURLConfirmremoveBrowserProfileremoveLocalStoragerestartExamPasswordProtectedrestartExamTextrestartExamURLrestartExamUseStartURLsebConfigPurpose0sebServicePolicy2sendBrowserExamKeyshowBackToStartButtonshowInputLanguageshowMenuBarshowNavigationButtonsshowReloadButtonshowReloadWarningshowScanQRCodeButtonshowSettingsInAppshowTaskBarshowTimestartResourcetaskBarHeight40touchOptimizedURLFilterEnableURLFilterEnableContentFilterURLFilterMessage0URLFilterRulesuseAsymmetricOnlyEncryptionwhitelistURLFilterzoomMode0", +// xmlString); } }