use of exceptions.AutomationException in project cvs-auto-svc by dvsa.
the class AwsUtil method getNextTrailerIdInSequence.
public static String getNextTrailerIdInSequence() {
Regions clientRegion = Regions.EU_WEST_1;
AWSSecurityTokenService stsClient = AWSSecurityTokenServiceClientBuilder.standard().withRegion(clientRegion).build();
String uuid = String.valueOf(UUID.randomUUID());
AssumeRoleRequest assumeRequest = new AssumeRoleRequest().withRoleArn(System.getProperty("AWS_ROLE")).withDurationSeconds(3600).withRoleSessionName(uuid);
AssumeRoleResult assumeResult = stsClient.assumeRole(assumeRequest);
BasicSessionCredentials temporaryCredentials = new BasicSessionCredentials(assumeResult.getCredentials().getAccessKeyId(), assumeResult.getCredentials().getSecretAccessKey(), assumeResult.getCredentials().getSessionToken());
AmazonDynamoDBClient client = new AmazonDynamoDBClient(temporaryCredentials);
client.setRegion(Region.getRegion(clientRegion));
DynamoDB dynamoDB = new DynamoDB(client);
String tableName = "cvs-" + loader.getBranchName() + "-test-number";
Table table = dynamoDB.getTable(tableName);
ItemCollection<ScanOutcome> items = // FilterExpression
table.scan(// FilterExpression
"attribute_exists(trailerId)", // ProjectionExpression
"trailerId, sequenceNumber, trailerLetter", // ExpressionAttributeNames - not used in this example
null, // ExpressionAttributeValues - not used in this example
null);
System.out.println("Scan of " + tableName + " for items with trailerId not null");
Iterator<Item> iterator = items.iterator();
String dynamoInfo = null;
while (iterator.hasNext()) {
dynamoInfo = iterator.next().toJSONPretty();
}
int lastTrailerSequenceNumberUsed = GenericData.extractIntegerValueFromJsonString(dynamoInfo, "$.sequenceNumber");
String trailerLetter = GenericData.getValueFromJsonPath(dynamoInfo, "$.trailerLetter");
if (lastTrailerSequenceNumberUsed != 0 && trailerLetter != null) {
int nextTrailerNumberInSequence = lastTrailerSequenceNumberUsed + 1;
return trailerLetter + nextTrailerNumberInSequence;
} else {
throw new AutomationException("No value found for last used sequence number or trailer letter");
}
}
use of exceptions.AutomationException in project cvs-auto-svc by dvsa.
the class WriterReader method getToken.
public static String getToken() {
FileUtils fileUtils;
File file = new File(FILE_NAME);
if (!file.exists()) {
saveUtils();
}
try (FileInputStream fi = new FileInputStream(file);
ObjectInputStream oi = new ObjectInputStream(fi)) {
fileUtils = (FileUtils) oi.readObject();
} catch (IOException e) {
e.printStackTrace();
throw new AutomationException("File Utils not found");
} catch (ClassNotFoundException e) {
e.printStackTrace();
throw new AutomationException("Error initializing stream");
}
return fileUtils.getToken();
}
use of exceptions.AutomationException in project cvs-auto-svc by dvsa.
the class TestTypeSteps method validateData.
@Step
public void validateData(TestTypeById testTypeById, List<TestTypeField> testTypeFields) {
int expectedResponseSize = 1;
response.then().body("id", equalTo(testTypeById.getId()));
if (testTypeFields != null) {
expectedResponseSize = expectedResponseSize + testTypeFields.size();
for (TestTypeField testTypeField : testTypeFields) {
switch(testTypeField) {
case DEFAULT_TEST_CODE:
response.then().body(testTypeField.getField(), equalTo(testTypeById.getDefaultTestCode()));
break;
case TEST_TYPE_CLASSIFICATION:
response.then().body(testTypeField.getField(), equalTo(testTypeById.getTestTypeClassification()));
break;
case LINKED_TEST_CODE:
response.then().body(testTypeField.getField(), equalTo(testTypeById.getLinkedTestCode()));
break;
case INVALID:
response.then().body("$", not(hasKey(testTypeField.getField())));
expectedResponseSize--;
break;
default:
throw new AutomationException("Field is" + testTypeField.getField() + " not present in automation please update step");
}
}
}
response.then().body("size()", equalTo(expectedResponseSize));
}
use of exceptions.AutomationException in project cvs-auto-svc by dvsa.
the class TestResultsClient method createTestRecord.
public String createTestRecord(String testStatus, String testResult, String testCode, boolean withWithoutDefects, Map<String, Object> testResultAttributes) {
List<JsonPathAlteration> testResultAlterations = new ArrayList<>();
String testResultPayloadFile = "test-results_" + testResultAttributes.get("vehicleType").toString() + ".json";
for (TestTypes testType : TestTypes.values()) {
if (testType.getTestCode().contentEquals(testCode.toLowerCase())) {
String testTypeId = testType.getId();
// create test result alteration to change testTypeId
JsonPathAlteration alterationTestTypeId = new JsonPathAlteration("$.testTypes[0].testTypeId", testTypeId, "", "REPLACE");
testResultAlterations.add(alterationTestTypeId);
String testTypeName = GenericData.readJsonValueFromFile("test-type.json", "$..[?(@.id =='" + testTypeId + "')].testTypeName");
// create test result alteration to change testTypeName
JsonPathAlteration alterationTestTypeName = new JsonPathAlteration("$.testTypes[0].testTypeName", testTypeName, "", "REPLACE");
testResultAlterations.add(alterationTestTypeName);
String testName = GenericData.readJsonValueFromFile("test-type.json", "$..[?(@.id =='" + testTypeId + "')].name");
// create test result alteration to change testName
JsonPathAlteration alterationTestName = new JsonPathAlteration("$.testTypes[0].name", testName, "", "REPLACE");
testResultAlterations.add(alterationTestName);
break;
}
}
// CREATE TEST RESULT RECORD
String postTestResultBody = GenericData.readJsonValueFromFile(testResultPayloadFile, "$");
String testResultId = UUID.randomUUID().toString();
// create alteration to change testStatus
JsonPathAlteration alterationTestStatus = new JsonPathAlteration("$.testStatus", testStatus, "", "REPLACE");
// create alteration to change testResultId
JsonPathAlteration alterationTestResultId = new JsonPathAlteration("$.testResultId", testResultId, "", "REPLACE");
// create alteration to change testResult
JsonPathAlteration alterationTestResult = new JsonPathAlteration("$.testTypes[0].testResult", testResult, "", "REPLACE");
JsonPathAlteration alterationPreparerName = new JsonPathAlteration("$.preparerName", "test", "", "REPLACE");
LocalDateTime currentDate = LocalDateTime.now(ZoneId.of("Europe/London"));
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
String endDate = currentDate.plusMinutes(50).format(formatter);
String expiryDate = currentDate.plusYears(1).format(formatter);
// create alteration to change testStartTimestamp
JsonPathAlteration alterationTestStartTimestamp = new JsonPathAlteration("$.testStartTimestamp", currentDate.format(formatter), "", "REPLACE");
// create alteration to change testEndTimestamp
JsonPathAlteration alterationTestEndTimestamp = new JsonPathAlteration("$.testEndTimestamp", endDate, "", "REPLACE");
JsonPathAlteration alterationTestTypeStartTimestamp = new JsonPathAlteration("$.testTypes[0].testTypeStartTimestamp", currentDate.format(formatter), "", "REPLACE");
// create alteration to change testTypeEndTimestamp
JsonPathAlteration alterationTestTypeEndTimestamp = new JsonPathAlteration("$.testTypes[0].testTypeEndTimestamp", endDate, "", "REPLACE");
// create alteration to change testExpiryDate
JsonPathAlteration alterationTestExpiryDate = new JsonPathAlteration("$.testTypes[0].testExpiryDate", expiryDate, "", "REPLACE");
if (!(testResult.toLowerCase().contentEquals("pass"))) {
alterationTestExpiryDate = new JsonPathAlteration("$.testTypes[0].testExpiryDate", "", "", "DELETE");
}
// Iterate over the HashMap to add all alteration for common attributes on tech records and test results
for (Map.Entry<String, Object> entry : testResultAttributes.entrySet()) {
JsonPathAlteration additionalTestResultAlteration = new JsonPathAlteration("$." + entry.getKey(), entry.getValue(), "", "REPLACE");
testResultAlterations.add(additionalTestResultAlteration);
}
// add remaining alterations to list of test result alterations
testResultAlterations.addAll(new ArrayList<>(Arrays.asList(alterationTestStatus, alterationTestResultId, alterationTestResult, alterationTestExpiryDate, alterationTestStartTimestamp, alterationTestEndTimestamp, alterationTestTypeStartTimestamp, alterationTestTypeEndTimestamp)));
// add alteration for adding
DocumentContext jsonContext = JsonPath.parse(postTestResultBody);
HashMap testType = jsonContext.read("$.testTypes[0]");
if (!(testType.containsKey("certficateNumber"))) {
if ((testCode.toLowerCase().contentEquals("tiv")) || (testCode.toLowerCase().contentEquals("tit")) || (testCode.toLowerCase().contentEquals("trv")) || (testCode.toLowerCase().contentEquals("trt")) || (testCode.toLowerCase().contentEquals("rft")) || (testCode.toLowerCase().contentEquals("ddv")) || (testCode.toLowerCase().contentEquals("ddt")) || (testCode.toLowerCase().contentEquals("arv")) || (testCode.toLowerCase().contentEquals("art")) || (testCode.toLowerCase().contentEquals("drv")) || (testCode.toLowerCase().contentEquals("drt"))) {
JsonPathAlteration alterationAddCertificateNumber = new JsonPathAlteration("$.testTypes[0]", "12345678", "certificateNumber", "ADD_FIELD");
testResultAlterations.add(alterationAddCertificateNumber);
}
}
if (testResult.toLowerCase().contentEquals("abandoned")) {
// create alteration to change reasonForAbandoning
JsonPathAlteration alterationReasonForAbandoning = new JsonPathAlteration("$.testTypes[0].reasonForAbandoning", "reason for abandoning", "", "REPLACE");
// create alteration to change additionalCommentsForAbandon
JsonPathAlteration alterationAdditionalCommentsForAbandon = new JsonPathAlteration("$.testTypes[0].additionalCommentsForAbandon", "additional comments for abandon", "", "REPLACE");
testResultAlterations.add(alterationReasonForAbandoning);
testResultAlterations.add(alterationAdditionalCommentsForAbandon);
}
if (!withWithoutDefects) {
// create alteration to remove defects
JsonPathAlteration alterationDefects = new JsonPathAlteration("$.testTypes[0].defects", "[]", "", "REPLACE");
testResultAlterations.add(alterationDefects);
}
Response responsePostTestResults = postVehicleTestResultsWithAlterations(postTestResultBody, testResultAlterations);
if (responsePostTestResults.statusCode() != 201) {
responsePostTestResults.prettyPrint();
throw new AutomationException("The post test results request was not successful, status code was " + responsePostTestResults.statusCode());
}
return testResultId;
}
use of exceptions.AutomationException in project cvs-auto-svc by dvsa.
the class ActivitiesClient method postActivitiesFieldChange.
public Response postActivitiesFieldChange(Activities activities, String propertyField, String value, ToTypeConvertor toType) {
ObjectMapper objectMapper = new ObjectMapper();
ObjectNode node = objectMapper.valueToTree(activities);
if (activities != null) {
for (Field field : ActivitiesGet.class.getDeclaredFields()) {
node.remove(field.getName());
}
}
switch(toType) {
case INTEGER:
node.put(propertyField, Integer.valueOf(value));
break;
case NULL:
node.putNull(propertyField);
break;
case MISSING:
node.remove(propertyField);
break;
case NEW_PROPERTY:
node.put(propertyField, value);
break;
default:
throw new AutomationException("Convert type not supported for Activities");
}
Response response = callPostActivities(node);
if (response.getStatusCode() == 401 || response.getStatusCode() == 403) {
saveUtils();
response = callPostActivities(node);
}
return response;
}
Aggregations