BasicPModeValidator implements IPModeValidator { @Override public Collection<PModeValidationError> validatePMode(final IPMode pmode) { Collection<PModeValidationError> errors = new ArrayList<>(); errors.addAll(checkGeneralParameters(pmode)); errors.addAll(checkSecurityParameters(pmode)); errors.addAll(checkPullingMPCs(pmode)); return errors; }  @Override String getName(); @Override boolean doesValidate(String pmodeType); @Override Collection<PModeValidationError> validatePMode(final IPMode pmode);  }
@Test public void testMinimalValidPMode() { PMode validPMode = new PMode(); validPMode.setMep(EbMSConstants.ONE_WAY_MEP); validPMode.setMepBinding(EbMSConstants.ONE_WAY_PUSH); validPMode.addLeg(new Leg()); assertTrue(Utils.isNullOrEmpty(validator.validatePMode(validPMode))); }
@Test public void testValidPModeWithSecurity() { PMode validPMode = new PMode(); validPMode.setMep(EbMSConstants.TWO_WAY_MEP); validPMode.setMepBinding(EbMSConstants.TWO_WAY_PUSH_PULL); PartnerConfig initiator = new PartnerConfig(); SecurityConfig secConfig = new SecurityConfig(); SigningConfig sigConfig = new SigningConfig(); sigConfig.setKeystoreAlias("exampleca"); secConfig.setSignatureConfiguration(sigConfig); EncryptionConfig encConfig = new EncryptionConfig(); encConfig.setKeystoreAlias("partya"); secConfig.setEncryptionConfiguration(encConfig); initiator.setSecurityConfiguration(secConfig); validPMode.setInitiator(initiator); UsernameTokenConfig tokenConfig = new UsernameTokenConfig(); tokenConfig.setUsername("username"); tokenConfig.setPassword("secret"); PartnerConfig responder = new PartnerConfig(); secConfig = new SecurityConfig(); sigConfig = new SigningConfig(); sigConfig.setKeystoreAlias("partyb"); sigConfig.setCertificatePassword("ExampleB"); secConfig.setSignatureConfiguration(sigConfig); encConfig = new EncryptionConfig(); encConfig.setKeystoreAlias("partyb"); encConfig.setCertificatePassword("ExampleB"); secConfig.setEncryptionConfiguration(encConfig); responder.setSecurityConfiguration(secConfig); validPMode.setResponder(responder); validPMode.addLeg(new Leg()); Leg leg = new Leg(); PullRequestFlow prFlow = new PullRequestFlow(); prFlow.setMPC("sub-MPC"); secConfig = new SecurityConfig(); sigConfig = new SigningConfig(); sigConfig.setKeystoreAlias("partyc"); secConfig.setSignatureConfiguration(sigConfig); prFlow.setSecurityConfiguration(secConfig); leg.addPullRequestFlow(prFlow); validPMode.addLeg(leg); assertTrue(Utils.isNullOrEmpty(validator.validatePMode(validPMode))); }
@Test public void testValidMultiplePRFlows() { PMode validPMode = new PMode(); validPMode.setMep(EbMSConstants.ONE_WAY_MEP); validPMode.setMepBinding(EbMSConstants.ONE_WAY_PULL); Leg leg = new Leg(); PullRequestFlow prFlow = new PullRequestFlow(); prFlow.setMPC(EbMSConstants.DEFAULT_MPC + "/sub-MPC-1"); leg.addPullRequestFlow(prFlow); prFlow = new PullRequestFlow(); prFlow.setMPC(EbMSConstants.DEFAULT_MPC + "/sub-MPC-2"); leg.addPullRequestFlow(prFlow); prFlow = new PullRequestFlow(); prFlow.setMPC(EbMSConstants.DEFAULT_MPC + "/sub-MPC-3"); leg.addPullRequestFlow(prFlow); validPMode.addLeg(leg); assertTrue(Utils.isNullOrEmpty(validator.validatePMode(validPMode))); validPMode = new PMode(); validPMode.setMep(EbMSConstants.ONE_WAY_MEP); validPMode.setMepBinding(EbMSConstants.ONE_WAY_PULL); leg = new Leg(); UserMessageFlow umFlow = new UserMessageFlow(); BusinessInfo busInfo = new BusinessInfo(); busInfo.setMpc("MPC"); umFlow.setBusinnessInfo(busInfo); leg.setUserMessageFlow(umFlow); prFlow = new PullRequestFlow(); prFlow.setMPC("MPC-1"); leg.addPullRequestFlow(prFlow); prFlow = new PullRequestFlow(); prFlow.setMPC("MPC-2"); leg.addPullRequestFlow(prFlow); prFlow = new PullRequestFlow(); prFlow.setMPC("MPC-3"); leg.addPullRequestFlow(prFlow); validPMode.addLeg(leg); assertTrue(Utils.isNullOrEmpty(validator.validatePMode(validPMode))); }
@Test public void testInvalidGeneralParameters() { PMode invalidPMode = new PMode(); invalidPMode.setMep(EbMSConstants.ONE_WAY_MEP+"/smth"); invalidPMode.setMepBinding(EbMSConstants.ONE_WAY_PUSH); invalidPMode.addLeg(new Leg()); assertFalse(Utils.isNullOrEmpty(validator.validatePMode(invalidPMode))); invalidPMode.setMep(EbMSConstants.ONE_WAY_MEP); assertTrue(Utils.isNullOrEmpty(validator.validatePMode(invalidPMode))); invalidPMode.setMepBinding(EbMSConstants.ONE_WAY_PUSH + "/smth"); assertFalse(Utils.isNullOrEmpty(validator.validatePMode(invalidPMode))); invalidPMode.setMepBinding(EbMSConstants.ONE_WAY_PUSH); assertTrue(Utils.isNullOrEmpty(validator.validatePMode(invalidPMode))); invalidPMode.addLeg(new Leg()); assertFalse(Utils.isNullOrEmpty(validator.validatePMode(invalidPMode))); invalidPMode.setLegs(null); invalidPMode.setMep(EbMSConstants.TWO_WAY_MEP); invalidPMode.addLeg(new Leg()); assertFalse(Utils.isNullOrEmpty(validator.validatePMode(invalidPMode))); }
@Test public void testInvalidUsernameTokenParameters() { PMode invalidPMode = new PMode(); invalidPMode.setMep(EbMSConstants.ONE_WAY_MEP); invalidPMode.setMepBinding(EbMSConstants.ONE_WAY_PUSH); invalidPMode.addLeg(new Leg()); assertTrue(Utils.isNullOrEmpty(validator.validatePMode(invalidPMode))); PartnerConfig initiator = new PartnerConfig(); SecurityConfig secConfig = new SecurityConfig(); SigningConfig sigConfig = new SigningConfig(); sigConfig.setKeystoreAlias("exampleca"); secConfig.setSignatureConfiguration(sigConfig); EncryptionConfig encConfig = new EncryptionConfig(); encConfig.setKeystoreAlias("partya"); secConfig.setEncryptionConfiguration(encConfig); initiator.setSecurityConfiguration(secConfig); invalidPMode.setInitiator(initiator); UsernameTokenConfig tokenConfig = new UsernameTokenConfig(); assertTrue(Utils.isNullOrEmpty(tokenConfig.getUsername())); secConfig.setUsernameTokenConfiguration( SecurityHeaderTarget.DEFAULT, tokenConfig); assertFalse(Utils.isNullOrEmpty(validator.validatePMode(invalidPMode))); tokenConfig.setUsername("username"); tokenConfig.setPassword("secret"); assertTrue(Utils.isNullOrEmpty(validator.validatePMode(invalidPMode))); tokenConfig = new UsernameTokenConfig(); secConfig.setUsernameTokenConfiguration( SecurityHeaderTarget.EBMS, tokenConfig); assertFalse(Utils.isNullOrEmpty(validator.validatePMode(invalidPMode))); }
@Test public void testInvalidX509Parameters() { PMode invalidPMode = TestUtils.create1WaySendPushPMode(); PartnerConfig initiator = new PartnerConfig(); SecurityConfig secConfig = new SecurityConfig(); SigningConfig sigConfig = new SigningConfig(); secConfig.setSignatureConfiguration(sigConfig); EncryptionConfig encConfig = new EncryptionConfig(); secConfig.setEncryptionConfiguration(encConfig); initiator.setSecurityConfiguration(secConfig); invalidPMode.setInitiator(initiator); assertFalse(Utils.isNullOrEmpty(validator.validatePMode(invalidPMode))); encConfig.setKeystoreAlias("partya"); assertFalse(Utils.isNullOrEmpty(validator.validatePMode(invalidPMode))); encConfig.setCertificatePassword("ExampleA"); assertFalse(Utils.isNullOrEmpty(validator.validatePMode(invalidPMode))); sigConfig.setKeystoreAlias("partyb"); assertNotNull(sigConfig.getKeystoreAlias()); assertFalse(Utils.isNullOrEmpty(validator.validatePMode(invalidPMode))); sigConfig.setCertificatePassword("ExampleB"); assertTrue(Utils.isNullOrEmpty(validator.validatePMode(invalidPMode))); }