Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initial functional tests commit #185

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

initial functional tests commit #185

wants to merge 4 commits into from

Conversation

hemantt
Copy link
Collaborator

@hemantt hemantt commented Jul 3, 2023

Before creating a pull request make sure that:

  • commit messages are meaningful and follow good commit message guidelines
  • README and other documentation has been updated / added (if needed)
  • tests have been updated / new tests has been added (if needed)

Please remove this line and everything above and fill the following sections:

JIRA link (if applicable)

Change description

Does this PR introduce a breaking change? (check one with "x")

[ ] Yes
[ ] No

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this IDE settings file be included?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this file needed? It's a Java class file with a .txt extension so may be a temporary file. If it is needed then there's a number of commented out lines of code in it that will need to be looked at.

@@ -0,0 +1,23 @@
package functions;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally speaking, the package structure should mirror that of the main source classes. Store the functional test classes under src/functionalTest/java/uk/gov/moj/sdt so that the package for this class becomes uk.gov.moj.sdt.functions.

The same comment applies to all the other classes.

Comment on lines +3 to +8
import net.thucydides.core.annotations.Step;
import io.restassured.RestAssured;
import io.restassured.response.Response;

import java.nio.file.Files;
import java.nio.file.Paths;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Organise these imports. If you're using Visual Studio Code the shortcut is option + shift + o (assuming you are using a Mac).

Comment on lines +9 to +10


Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove one of these blank lines.

Comment on lines +19 to +24
String xmlContent = "";
try {
xmlContent = new String(Files.readAllBytes(Paths.get(getClass().getClassLoader().getResource("statusUpdate.xml").toURI())));
} catch (Exception e) {
e.printStackTrace();
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code for reading a file is duplicated in the IssueWarrant and MCOLJudgment classes. It would be better to put it in a method in a separate utility class and call that instead.

In the event of an exception being raised it would be better to fail the test rather than handling it and carrying on as is done here. This would make it easier to debug. In JUnit you can explicitly fail a test using org.junit.jupiter.api.Assertions.fail - I don't know if Serenity offers an equivalent. If not you could just let the method throw the exception by adding throws <exception class name> to the signature.

e.printStackTrace();
}

randomNumber = (int)(Math.random() * 10000); // Generate a random number
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the XMLFunctions.generateRandomNumber() method here rather than duplicating the code in it.

Comment on lines +50 to +60
public String removeNamespaces(String xmlResponse) {
return xmlResponse.replaceAll("xmlns.*?(\"|\').*?(\"|\')", "")
.replaceAll("(<)(\\w+:)(.*?>)", "$1$3")
.replaceAll("(</)(\\w+:)(.*?>)", "$1$3");
}

public String getCleanResponse() {
String xmlResponse = response.asString();
xmlResponse = removeNamespaces(xmlResponse);
return xmlResponse;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These methods don't appear to be used and are duplicates of those on the XMLFunctions class. Remove them from this class.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Organise the imports on this class (see comment for ClaimStatusSteps class).

Comment on lines +3 to +5
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are JUnit4 classes. Replace them with the JUnit5 equivalents:

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

More details about replacing @RunWith with @ExtendWith can be found in the comment for that line.

import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.matchesRegex;
import static org.hamcrest.CoreMatchers.containsString;
import org.junit.jupiter.api.Assertions;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace this with import static org.junit.jupiter.api.Assertions.assertEquals. You'll then be able to remove Assertions. from before assertEquals() on line 34.

import steps.ClaimStatusSteps;


@RunWith(SerenityRunner.class)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be replaced with the JUnit5 equivalent which is @ExtendWith(SerenityJUnit5Extension.class)

Comment on lines +14 to +15


Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove one of these blank lines.

@Steps
ClaimStatusSteps claimStatusSteps;

@Before
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change this to @BeforeEach (the JUnit5 equivalent).


@Test
public void claimStatusUpdateResponseCode() {
XmlPath xmlPath = new XmlPath(claimStatusSteps.getCleanResponse()).setRoot("Envelope.Body.bulkResponse");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create a constant for Envelope.Body.bulkResponse and use that instead. As it's also used in the MCOLJudgment and IssueWarrant classes you may want to create it as a public constant on a new parent class and have the three classes inherit from it.


assertThat(xmlResponseCode, equalTo("Ok"));
Assertions.assertEquals(200, claimStatusSteps.getResponse().getStatusCode());

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this blank line.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Class needs to have a package line saying what package it is in.

Note that convention states that package names should all be in lower case. It would also make sense to create an "operations" package into which the get bulk feedback and submit bulk packages can be placed to group them logically. Taking this into account, and the comment about package names for the XMLFunctions class, I'd suggest the following package structure:

uk.gov.moj.sdt.operations
uk.gov.moj.sdt.operations.getbulkfeedback
uk.gov.moj.sdt.operations.submitbulk

The package line for this class would therefore be:
package uk.gov.moj.sdt.operations.submitbulk;

XmlPath xmlPath = new XmlPath(claimStatusSteps.getCleanResponse()).setRoot("Envelope.Body.bulkResponse");
String sdtBulkReference = xmlPath.getString("sdtBulkReference");

assertThat(sdtBulkReference, matchesRegex("MCOL-\\d+-\\d+"));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The regular expression can be changed to MCOL-\\d{14}-\\d{9} (i.e. the second part should be exactly 14 digits and the third part exactly 9 digits) to more accurately reflect the format - see SdtBulkReferenceGenerator.getSdtBulkReference.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The following previously made comments apply to this class:

  • Reorganise class into the uk.gov.moj.sdt.operations.submitbulk package
  • Add the package line
  • Replace the JUnit4 imports with the JUnit5 equivalents and change code accordingly
  • Organise the imports

Comment on lines +23 to +24


Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove one of these blank lines.

Comment on lines +92 to +97
System.out.println("xmlResponseCode: " + xmlResponseCode);
System.out.println("Customer Reference: " + customerReference);
System.out.println("SDT Bulk Reference: " + sdtBulkReference);
System.out.println("Submitted Date: " + submittedDate);
System.out.println("SDT Service: " + sdtService);
System.out.println("Request Count: " + requestCount);
Copy link
Collaborator

@paulridout paulridout Jul 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove these System.out lines - they will be flagged by Sonar as an issue. If they really need to be output then consider the use of a logger (for an example see SubmitBulkForSystemTest class lines 48 and 81).

If there's no need to output the values then the variables on lines 85 to 89 can also be removed, unless the test is going to be changed to check the values of them.

String custId = "10000002";
String requestCount = "1";
private String custIDInvalidErrorCode = "CUST_ID_INVALID";
private String sdtBulkReferenceRegex = "MCOL-\\d+-\\d+";
Copy link
Collaborator

@paulridout paulridout Jul 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regular expression can be changed to MCOL-\\d{14}-\\d{9}.

Comment on lines +126 to +129
custId = "12345678";
setUp();

XmlPath xmlPath = new XmlPath(XMLFunctions.getCleanResponse(response)).setRoot("Envelope.Body.bulkResponse");
Copy link
Collaborator

@paulridout paulridout Jul 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing the custId class field value like this will cause problems with subsequent tests. The custId value is never set back to the correct value afterwards, so the tests that run after will always fail with an invalid customer id error.

To prevent potential errors it might be an idea to make the following changes:

1.) Add randomNumber, custId and requestCount parameters to the soapRequestBody() method.
2.) Instead of calling setUp() here, call the soapRequestBody() method with the new customer id value, followed by soapResponse().

The advantage with this is that you won't need to remember to reset the custId field at the end of the test. It also guards against the case when the test fails due to an exception before the custId field can be reset.

Comment on lines +141 to +144
requestCount = "2";
setUp();

XmlPath xmlPath = new XmlPath(XMLFunctions.getCleanResponse(response)).setRoot("Envelope.Body.bulkResponse");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment applies here as for the validateCustID() test. The same suggested solution will work here too.

Comment on lines +153 to +165
// @Test
// public void issueWarrantResponseDescription() {

// checkStatusCode(response);

// String xmlResponse = response.asString();
// xmlResponse = removeNamespaces(xmlResponse);

// XmlPath xmlPath = new XmlPath(xmlResponse).setRoot("Envelope.Body.bulkResponse.status.error");
// String errorDescription = xmlPath.getString("description");

// assertThat(errorDescription, containsString("Duplicate User File Reference 91 supplied"));
// }
Copy link
Collaborator

@paulridout paulridout Jul 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this needed? If the test is valid but can't yet be run because of some other issue then uncomment it and annotate it with the JUnit @Disabled annotation. It's also recommended to add a comment to the annotation explaining why it's disabled, e.g.

@Disabled("Disabled until warrant functionality fixed")

If the test is not needed then delete it.

System.out.println("Request Count: " + requestCount);

assertThat(xmlResponseCode, equalTo("Ok"));
Assertions.assertEquals(200, statusCode);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could the checkStatusCode() method be used here instead of assertEquals()?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The following previously made comments apply to this class:

  • Reorganise class into the uk.gov.moj.sdt.operations.submitbulk package
  • Add the package line
  • Replace the JUnit4 imports with the JUnit5 equivalents and change code accordingly
  • Organise the imports

Comment on lines +22 to +23


Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove one of these blank lines.

e.printStackTrace();
}

randomNumber = (int)(Math.random() * 1000000); // Generate a random number
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace this with a call to XMLFunctions.generateRandomNumber()

Comment on lines +64 to +68
public String removeNamespaces(String xmlResponse) {
return xmlResponse.replaceAll("xmlns.*?(\"|\').*?(\"|\')", "")
.replaceAll("(<)(\\w+:)(.*?>)", "$1$3")
.replaceAll("(</)(\\w+:)(.*?>)", "$1$3");
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this and use XMLFunctions.removeNamespaces() instead.

Comment on lines +76 to +80
public String getCleanResponse() {
String xmlResponse = response.asString();
xmlResponse = removeNamespaces(xmlResponse);
return xmlResponse;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this and use XMLFunctions.getCleanResponse() instead.

Comment on lines +94 to +99
System.out.println("xmlResponseCode: " + xmlResponseCode);
System.out.println("Customer Reference: " + customerReference);
System.out.println("SDT Bulk Reference: " + sdtBulkReference);
System.out.println("Submitted Date: " + submittedDate);
System.out.println("SDT Service: " + sdtService);
System.out.println("Request Count: " + requestCount);
Copy link
Collaborator

@paulridout paulridout Jul 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove these System.out lines - they will be flagged by Sonar as an issue. If they really need to be output then consider the use of a logger (for an example see SubmitBulkForSystemTest class lines 48 and 81).

If there's no need to output the values then the variables on lines 87 to 91 can also be removed, unless the test is going to be changed to check the values of them.

XmlPath xmlPath = new XmlPath(getCleanResponse()).setRoot("Envelope.Body.bulkResponse");
String sdtBulkReference = xmlPath.getString("sdtBulkReference");

assertThat(sdtBulkReference, matchesRegex("MCOL-\\d+-\\d+"));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regular expression can be changed to MCOL-\\d{14}-\\d{9}.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the test methods in this class have "Warrant" in the name. They should be changed to "Judgment" instead (probably a copy/paste issue).

Comment on lines +125 to +137
// @Test
// public void issueWarrantResponseDescription() {

// checkStatusCode(response);

// String xmlResponse = response.asString();
// xmlResponse = removeNamespaces(xmlResponse);

// XmlPath xmlPath = new XmlPath(xmlResponse).setRoot("Envelope.Body.bulkResponse.status.error");
// String errorDescription = xmlPath.getString("description");

// assertThat(errorDescription, containsString("Duplicate User File Reference 91 supplied"));
// }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this needed? If the test is valid but can't yet be run because of some other issue then uncomment it and annotate it with the JUnit @Disabled annotation. It's also recommended to add a comment to the annotation explaining why it's disabled.

If the test is not needed then delete it.

System.out.println("Request Count: " + requestCount);

assertThat(xmlResponseCode, equalTo("Ok"));
Assertions.assertEquals(200, statusCode);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this use checkStatusCode() instead?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be empty and is it needed? No tests reference this file.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this file needed? There don't appear to be any tests that use it.

<!-- Defendant id must be 1 or 2 -->
<brthsp:defendantId>1</brthsp:defendantId>
<!-- Breathing space notification type must be BS, BC, MH or MC -->
<brthsp:breathingSpaceNotificationType>BT</brthsp:breathingSpaceNotificationType>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this file is needed, note that the breathing space type here is an invalid one. The valid types are given in the comment above.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this file needed? There don't appear to be any tests that use it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this file needed? There don't appear to be any tests that use it.

If the file is needed then the name should be "combinedJudgmentWarrant".

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the validGetBulkFeedback class isn't reinstated then it doesn't appear that this file is needed.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this file needed? There don't appear to be any tests that use it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this file needed? There don't appear to be any tests that use it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this file needed? There don't appear to be any tests that use it.

group = 'uk.gov.hmcts.civil.sdt'
version = '0.0.1'
sourceCompatibility = '11'
targetCompatibility = '11'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why we are using 11 only, can we use 17

implementation 'org.apache.xmlbeans:xmlbeans:3.1.0'
testImplementation 'net.serenity-bdd:serenity-core:3.2.0'
testImplementation 'net.serenity-bdd:serenity-junit:3.2.0'
testImplementation 'io.rest-assured:rest-assured:4.4.0'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use 5.3.1 version as this is latest

@@ -221,6 +229,14 @@ allprojects {
apply plugin: 'java'

dependencies {
implementation 'org.apache.xmlbeans:xmlbeans:3.1.0'
testImplementation 'net.serenity-bdd:serenity-core:3.2.0'
testImplementation 'net.serenity-bdd:serenity-junit:3.2.0'
Copy link
Collaborator

@kiran-yenigala-hmcts kiran-yenigala-hmcts Jul 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use 3.8.1 version as this is latest for serenity-core and serenity-junit

@@ -221,6 +229,14 @@ allprojects {
apply plugin: 'java'

dependencies {
implementation 'org.apache.xmlbeans:xmlbeans:3.1.0'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use 5.1.1 version as this is latest for xmlbeans

testImplementation 'io.rest-assured:rest-assured:4.4.0'
implementation 'io.rest-assured:json-path:4.4.0'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.2'
testImplementation 'org.junit.jupiter:junit-jupiter:5.7.2'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check these as well for the latest versions

@@ -0,0 +1,53 @@
import io.restassured.RestAssured;
import io.restassured.response.Response;
import net.serenitybdd.junit.runners.SerenityRunner;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why the name of the file ends with .txt

Copy link
Collaborator

@kiran-yenigala-hmcts kiran-yenigala-hmcts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor comments added

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants