NdsBeisEsb/src/test/java/com/northgateps/nds/beis/esb/passwordreset/BeisPasswordResetRouteTest.java
//test for passwordReset with same email address in ldap and backoffice

test for passwordReset with same email address in ldap and backoffice
test for passwordReset with same email address in ldap and backoffice
@Test
    public void testPasswordResetWithSameEmailAddressInBOAndLdap() throws Exception {
        final String emailTextLine1 = "You asked for your PRS exemptions account password to be reset. You now need to set a new password.";
        assumeTrue(connection);
        final BeisRegistrationDetails registeredUser = registerANewUser(mockDirectoryKernel);
        String username = registeredUser.getUserDetails().getUsername();
        context.getRouteDefinition(getPartyDetailsRouteName).adviceWith(context, new AdviceWithRouteBuilder() {
            @Override
            public void configure() throws Exception {
                interceptSendToEndpoint("cxf:bean:beisGetPartyDetailsService").skipSendToOriginalEndpoint().to(
                        MOCK_GET_PARTYDETAILS).process(new Processor() {
                    @Override
                    public void process(Exchange exchange) throws Exception {
                        GetPartyDetailsRequest request = (GetPartyDetailsRequest) exchange.getIn().getBody();
                        assertEquals("Checking party ref", BigInteger.valueOf(1366), request.getPartyRef());
                        exchange.getIn().setBody(createGetPartyDetailsResponse("a@beis.com"));
                    }
                });
            }
        });
        context.start();
        MockEndpoint requestMock = getMockEndpoint(MOCK_PASSWORD_RESET_REQUEST_CHECK);
        requestMock.reset();
        requestMock.expectedMessageCount(1);
        requestMock.expectedHeaderValuesReceivedInAnyOrder("subject", "Password reset");
        requestMock.whenAnyExchangeReceived(new Processor() {
            @Override
            public void process(Exchange exchange) throws Exception {
                String body = exchange.getIn().getBody(String.class);
                assertTrue("Check emailTextLine1", body.contains(emailTextLine1));
                assertEquals("Check email is sent to email address present in ldap", "a@beis.com", 
                        exchange.getIn().getHeader("to"));
            }
        });
        MockEndpoint passwordResetResponseMock = getMockEndpoint(MOCK_PASSWORD_RESET_RESPONSE_CHECK);
        passwordResetResponseMock.expectedMessageCount(1);
        passwordResetResponseMock.expectedBodiesReceived(JaxbXmlMarshaller.convertToPrettyPrintXml(
                createSuccessfulNdsPasswordResetResponse(), PasswordResetNdsResponse.class));
        String resetCode = generateResetCode(username);
        apiEndpoint.sendBody(createResetPasswordNdsRequestWithResetCode(username, resetCode));
        assertMockEndpointsSatisfied();
    }
@ Test public void testPasswordResetWithSameEmailAddressInBOAndLdap ( ) throws Exception { final String emailTextLine1 = "You asked for your PRS exemptions account password to be reset. You now need to set a new password." ; assumeTrue ( connection ) ; final BeisRegistrationDetails registeredUser = registerANewUser ( mockDirectoryKernel ) ; String username = registeredUser . getUserDetails ( ) . getUsername ( ) ; context . getRouteDefinition ( getPartyDetailsRouteName ) . adviceWith ( context , new AdviceWithRouteBuilder ( ) { @ Override public void configure ( ) throws Exception { interceptSendToEndpoint ( "cxf:bean:beisGetPartyDetailsService" ) . skipSendToOriginalEndpoint ( ) . to ( MOCK_GET_PARTYDETAILS ) . process ( new Processor ( ) { @ Override public void process ( Exchange exchange ) throws Exception { GetPartyDetailsRequest request = ( GetPartyDetailsRequest ) exchange . getIn ( ) . getBody ( ) ; assertEquals ( "Checking party ref" , BigInteger . valueOf ( 1366 ) , request . getPartyRef ( ) ) ; exchange . getIn ( ) . setBody ( createGetPartyDetailsResponse ( "a@beis.com" ) ) ; } } ) ; } } ) ; context . start ( ) ; MockEndpoint requestMock = getMockEndpoint ( MOCK_PASSWORD_RESET_REQUEST_CHECK ) ; requestMock . reset ( ) ; requestMock . expectedMessageCount ( 1 ) ; requestMock . expectedHeaderValuesReceivedInAnyOrder ( "subject" , "Password reset" ) ; requestMock . whenAnyExchangeReceived ( new Processor ( ) { @ Override public void process ( Exchange exchange ) throws Exception { String body = exchange . getIn ( ) . getBody ( String . class ) ; assertTrue ( "Check emailTextLine1" , body . contains ( emailTextLine1 ) ) ; assertEquals ( "Check email is sent to email address present in ldap" , "a@beis.com" , exchange . getIn ( ) . getHeader ( "to" ) ) ; } } ) ; MockEndpoint passwordResetResponseMock = getMockEndpoint ( MOCK_PASSWORD_RESET_RESPONSE_CHECK ) ; passwordResetResponseMock . expectedMessageCount ( 1 ) ; passwordResetResponseMock . expectedBodiesReceived ( JaxbXmlMarshaller . convertToPrettyPrintXml ( createSuccessfulNdsPasswordResetResponse ( ) , PasswordResetNdsResponse . class ) ) ; String resetCode = generateResetCode ( username ) ; apiEndpoint . sendBody ( createResetPasswordNdsRequestWithResetCode ( username , resetCode ) ) ; assertMockEndpointsSatisfied ( ) ; }
test for passwordReset with same email address in ldap and backoffice
test for passwordReset with same email address in ldap and backoffice
//assume connection is done for ldap
 //set the same email in response which is present in ldap
