Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Aug 30, 2023
1 parent 4dfe985 commit f2c0282
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 47 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ followed by the full path to a config file. For example:
```-DtcmsConfigPath=D:\Path\To\tcms.conf```

There are special keys that can be used to configure the reported test cases/plans:
- `runId` test cases will be reported under one ID specified as the value. Can be overwritten by setting
- `runId` test cases will be reported under one ID specified as the value. Can be overwritten by setting
environmental variable `TCMS_RUN_ID`
- `runName` if you don't like the built-in `[JUnit] Results for [Product], [ProductVersio], [Build]` test run name,
you can specify your own. Works only for newly registered runs. Can be overwritten by Maven option `tcmsRunName`
(ex.: `-DtcmsRunName=HelloWorld`)
- `product` test cases will be reported under specified product name. Can be overwritten by setting any
- `product` test cases will be reported under specified product name. Can be overwritten by setting any
of the env variables: `JOB_NAME`, `TRAVIS_REPO_SLUG` or `TCMS_PRODUCT`
- `productVer` test cases will be reported under specified product version. Can be overwritten by setting any
of the env variables: `TRAVIS_PULL_REQUEST_SHA`, `TRAVIS_COMMIT` or `TCMS_PRODUCT_VERSION`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
import java.lang.reflect.Method;

public class TcmsTestAttributesAnnotationProcessor {

private int value = 0;
private int testCaseId = 0;
private int productId = 0;
private int planId = 0;

Check warning on line 10 in src/main/java/org/kiwitcms/java/annotations/TcmsTestAttributesAnnotationProcessor.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/kiwitcms/java/annotations/TcmsTestAttributesAnnotationProcessor.java#L7-L10

Added lines #L7 - L10 were not covered by tests

public TcmsTestAttributesAnnotationProcessor(Class<?> annotatedClass) {

Check warning on line 12 in src/main/java/org/kiwitcms/java/annotations/TcmsTestAttributesAnnotationProcessor.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/kiwitcms/java/annotations/TcmsTestAttributesAnnotationProcessor.java#L12

Added line #L12 was not covered by tests
if (annotatedClass.isAnnotationPresent(TcmsTestAttributes.class)) {
TcmsTestAttributes classAttributes = annotatedClass.getAnnotation(TcmsTestAttributes.class);
Expand All @@ -18,7 +18,7 @@ public TcmsTestAttributesAnnotationProcessor(Class<?> annotatedClass) {
this.planId = classAttributes.planId();

Check warning on line 18 in src/main/java/org/kiwitcms/java/annotations/TcmsTestAttributesAnnotationProcessor.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/kiwitcms/java/annotations/TcmsTestAttributesAnnotationProcessor.java#L14-L18

Added lines #L14 - L18 were not covered by tests
}
}

Check warning on line 20 in src/main/java/org/kiwitcms/java/annotations/TcmsTestAttributesAnnotationProcessor.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/kiwitcms/java/annotations/TcmsTestAttributesAnnotationProcessor.java#L20

Added line #L20 was not covered by tests

public TcmsTestAttributesAnnotationProcessor(Method annotatedMethod) {

Check warning on line 22 in src/main/java/org/kiwitcms/java/annotations/TcmsTestAttributesAnnotationProcessor.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/kiwitcms/java/annotations/TcmsTestAttributesAnnotationProcessor.java#L22

Added line #L22 was not covered by tests
if (annotatedMethod.isAnnotationPresent(TcmsTestAttributes.class)) {
TcmsTestAttributes methodAttributes = annotatedMethod.getAnnotation(TcmsTestAttributes.class);
Expand All @@ -28,16 +28,16 @@ public TcmsTestAttributesAnnotationProcessor(Method annotatedMethod) {
this.planId = methodAttributes.planId();

Check warning on line 28 in src/main/java/org/kiwitcms/java/annotations/TcmsTestAttributesAnnotationProcessor.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/kiwitcms/java/annotations/TcmsTestAttributesAnnotationProcessor.java#L24-L28

Added lines #L24 - L28 were not covered by tests
}
}

Check warning on line 30 in src/main/java/org/kiwitcms/java/annotations/TcmsTestAttributesAnnotationProcessor.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/kiwitcms/java/annotations/TcmsTestAttributesAnnotationProcessor.java#L30

Added line #L30 was not covered by tests

public int getTestCaseId() {
if (this.testCaseId > 0) {return this.testCaseId;}
return Math.max(this.value, 0);

Check warning on line 34 in src/main/java/org/kiwitcms/java/annotations/TcmsTestAttributesAnnotationProcessor.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/kiwitcms/java/annotations/TcmsTestAttributesAnnotationProcessor.java#L34

Added line #L34 was not covered by tests
}

public int getProductId() {
return Math.max(this.productId, 0);

Check warning on line 38 in src/main/java/org/kiwitcms/java/annotations/TcmsTestAttributesAnnotationProcessor.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/kiwitcms/java/annotations/TcmsTestAttributesAnnotationProcessor.java#L38

Added line #L38 was not covered by tests
}

public int getPlanId() {
return Math.max(this.planId, 0);

Check warning on line 42 in src/main/java/org/kiwitcms/java/annotations/TcmsTestAttributesAnnotationProcessor.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/kiwitcms/java/annotations/TcmsTestAttributesAnnotationProcessor.java#L42

Added line #L42 was not covered by tests
}
Expand Down
38 changes: 19 additions & 19 deletions src/main/java/org/kiwitcms/java/api/RpcClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public TestCase getOrCreateTestCase(int productId, int categoryId, int priorityI
return null;
}
}

//TODO: test coverage
public TestRun createNewRun(int build, String manager, int plan, String summary) {
Map<String, Object> params = new HashMap<>();
Expand All @@ -123,7 +123,7 @@ public TestRun createNewRun(int build, String manager, int plan, String summary)
return null;
}
}

//TODO: test coverage
public TestCase[] getRunIdTestCases(int runId) {
JSONArray jsonArray = (JSONArray) executeViaPositionalParams(GET_RUN_TCS_METHOD, Arrays.asList((Object) runId));
Expand All @@ -134,7 +134,7 @@ public TestCase[] getRunIdTestCases(int runId) {
return new TestCase[0];
}
}

//TODO: test coverage
public TestExecution[] addTestCaseToRunId(int runId, int caseId) {
Map<String, Object> params = new HashMap<>();
Expand Down Expand Up @@ -164,7 +164,7 @@ public boolean planExists(int planId) {
JSONArray jsonArray = (JSONArray) executeViaPositionalParams(TEST_PLAN_FILTER, Arrays.asList((Object) filter));
return !jsonArray.isEmpty();
}

//TODO: test coverage
public int getTestPlanId(String name, int productId) {
Map<String, Object> filter = new HashMap<>();
Expand Down Expand Up @@ -202,7 +202,7 @@ public TestRun getRun(int runId) {
}
}
}

//TODO: test coverage
public TestPlan createNewTP(int productId, String name, int versionId) {
Map<String, Object> params = new HashMap<>();
Expand All @@ -225,7 +225,7 @@ public TestPlan createNewTP(int productId, String name, int versionId) {
return null;
}
}

//TODO: test coverage
public void addTestCaseToPlan(int planId, int caseId) {
Map<String, Object> filter = new HashMap<>();
Expand All @@ -252,7 +252,7 @@ public TestExecution getTestExecution(Map<String, Object> filter) {
}
}
}

//TODO: test coverage
public TestExecution updateTestExecution(int tcRunId, int status) {
Map<String, Object> values = new HashMap<>();
Expand All @@ -277,7 +277,7 @@ public JSONArray getTestCaseStatus(Map<String, Object> filter) {
JSONArray jsonArray = (JSONArray) executeViaPositionalParams(TEST_CASE_STATUS_FILTER, Arrays.asList((Object) filter));
return jsonArray;
}

//TODO: test coverage
//Get first available
public int getConfirmedTCStatusId() {
Expand All @@ -286,7 +286,7 @@ public int getConfirmedTCStatusId() {
Object id = ((JSONObject) getTestCaseStatus(confirmed_params).get(0)).get("id");
return Integer.parseInt(String.valueOf(id));
}

//TODO: test coverage
public Integer getProductId(String name) {
Map<String, Object> filter = new HashMap<>();
Expand All @@ -304,7 +304,7 @@ public Integer getProductId(String name) {
}
}
}

//TODO: test coverage
public Product createNewProduct(String name) {
Map<String, Object> params = new HashMap<>();
Expand All @@ -325,7 +325,7 @@ public Product createNewProduct(String name) {
return null;
}
}

//TODO: test coverage
public Build[] getBuilds(Map<String, Object> filter) {
JSONArray jsonArray = (JSONArray) executeViaPositionalParams(BUILD_FILTER, Arrays.asList((Object) filter));
Expand All @@ -341,7 +341,7 @@ public Build[] getBuilds(Map<String, Object> filter) {
}
}
}

//TODO: test coverage
public Build createBuild(String name, int versionId) {
Map<String, Object> params = new HashMap<>();
Expand All @@ -355,7 +355,7 @@ public Build createBuild(String name, int versionId) {
return null;
}
}

//TODO: test coverage
public Version[] getVersions(Map<String, Object> filter) {
JSONArray jsonArray = (JSONArray) executeViaPositionalParams(VERSION_FILTER, Arrays.asList((Object) filter));
Expand All @@ -371,7 +371,7 @@ public Version[] getVersions(Map<String, Object> filter) {
}
}
}

//TODO: test coverage
public Version createProductVersion(String version, int productId) {
Map<String, Object> params = new HashMap<>();
Expand All @@ -386,7 +386,7 @@ public Version createProductVersion(String version, int productId) {
return null;
}
}

//TODO: test coverage
public Priority[] getPriority(Map<String, Object> filter) {
JSONArray jsonArray = (JSONArray) executeViaPositionalParams(PRIORITY_FILTER, Arrays.asList((Object) filter));
Expand All @@ -401,13 +401,13 @@ public Priority[] getPriority(Map<String, Object> filter) {
}
}
}

//TODO: test coverage
// TODO: Create Category class
public JSONArray getCategory(Map<String, Object> filter) {
return (JSONArray) executeViaPositionalParams(CATEGORY_FILTER, Arrays.asList((Object) filter));
}

//TODO: test coverage
public TestExecutionStatus getTestExecutionStatus(String name, String weightLookup) {
Map<String, Object> filter = new HashMap<>();
Expand All @@ -430,7 +430,7 @@ public TestExecutionStatus getTestExecutionStatus(String name, String weightLook
return null;
}
}

public TestCase getTestCaseById(int testCaseId) {
Map<String, Object> filter = new HashMap<>();
filter.put("id", testCaseId);
Expand All @@ -439,7 +439,7 @@ public TestCase getTestCaseById(int testCaseId) {
System.out.printf("-- kiwitcms-junit-plugin -- Case ID \"%s\" not found%n", testCaseId);
return null;
}

try {
TestCase[] testCases = new ObjectMapper().readValue(jsonArray.toJSONString(), TestCase[].class);
return testCases[0];
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/kiwitcms/java/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public String getBuild() {
orElse(Optional.ofNullable(System.getenv("BUILD_NUMBER")).
orElse(config.node("tcms").get("build", null))));

Check warning on line 88 in src/main/java/org/kiwitcms/java/config/Config.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/kiwitcms/java/config/Config.java#L87-L88

Added lines #L87 - L88 were not covered by tests
}

public String getRunName() {
return Optional.ofNullable(System.getProperty("tcmsRunName")).
orElse(config.node("tcms").get("runName", null));

Check warning on line 93 in src/main/java/org/kiwitcms/java/config/Config.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/kiwitcms/java/config/Config.java#L92-L93

Added lines #L92 - L93 were not covered by tests
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/kiwitcms/java/junit/KiwiTcmsExtension.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void afterEach(ExtensionContext context) {
test.result = "PASS";
}
test.containingClass = method.getDeclaringClass().getSimpleName();

//Assign test attributes if present in annotations
TcmsTestAttributesAnnotationProcessor classAnnotation = new TcmsTestAttributesAnnotationProcessor(method.getDeclaringClass());
TcmsTestAttributesAnnotationProcessor methodAnnotation = new TcmsTestAttributesAnnotationProcessor(method);

Check warning on line 53 in src/main/java/org/kiwitcms/java/junit/KiwiTcmsExtension.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/kiwitcms/java/junit/KiwiTcmsExtension.java#L52-L53

Added lines #L52 - L53 were not covered by tests
Expand All @@ -66,7 +66,7 @@ public void afterEach(ExtensionContext context) {
if (classAnnotation.getPlanId() != 0 && methodAnnotation.getPlanId() != 0 && classAnnotation.getPlanId() != methodAnnotation.getPlanId()) {
test.testPlanId = methodAnnotation.getPlanId();

Check warning on line 67 in src/main/java/org/kiwitcms/java/junit/KiwiTcmsExtension.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/kiwitcms/java/junit/KiwiTcmsExtension.java#L67

Added line #L67 was not covered by tests
}

tests.add(test);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/kiwitcms/java/junit/TestDataEmitter.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,16 @@ public void addTestResultsToRun(int runId, List<TestMethod> tests) {
//Override values from annotation (if present and not 0)
int overridePlanId = test.testPlanId != 0 ? test.testPlanId : testPlanId;
int overrideProductId = test.productId != 0 ? test.productId : productId;

if (test.id != 0) {
testCase = client.getTestCaseById(test.id);

Check warning on line 112 in src/main/java/org/kiwitcms/java/junit/TestDataEmitter.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/kiwitcms/java/junit/TestDataEmitter.java#L112

Added line #L112 was not covered by tests
}
if (ObjectUtils.isEmpty(testCase)) {
testCase = client.getOrCreateTestCase(overrideProductId, categoryId, priorityId, test.getSummary());

Check warning on line 115 in src/main/java/org/kiwitcms/java/junit/TestDataEmitter.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/kiwitcms/java/junit/TestDataEmitter.java#L115

Added line #L115 was not covered by tests
}

client.addTestCaseToPlan(overridePlanId, testCase.getCaseId());

Check warning on line 118 in src/main/java/org/kiwitcms/java/junit/TestDataEmitter.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/kiwitcms/java/junit/TestDataEmitter.java#L118

Added line #L118 was not covered by tests

TestExecution[] executions = client.addTestCaseToRunId(runId, testCase.getCaseId());
for (TestExecution testExecution : executions) {
client.updateTestExecution(testExecution.getTcRunId(), getTestExecutionStatusId(test.result));
Expand Down
28 changes: 14 additions & 14 deletions src/test/java/org/kiwitcms/java/api/TestingRpcTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,16 @@ void getRunWhenServiceResponseMisformattedTest() {

assertThat(spy.getRun(1), is(equalTo(null)));
}

@Test
void getTestParametersByTestId() {
RpcClient spy = Mockito.spy(new RpcClient());

//TODO enable when date assignment in TestCase.class is working; returns null when mapping a valid date format
// Date date = Date.from(Instant.now());
// SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
// String formattedDate = sdf.format(date);

//Test object
JSONArray result = new JSONArray();
JSONObject resultBody = new JSONObject();
Expand Down Expand Up @@ -141,11 +141,11 @@ void getTestParametersByTestId() {
resultBody.put("setup_duration", 0.0);
resultBody.put("testing_duration", 0.0);
resultBody.put("expected_duration", 0.0);

result.add(resultBody);

Mockito.doReturn(result).when((BaseRpcClient) spy).executeViaPositionalParams(eq(TEST_CASE_FILTER), anyList());

//Expected test case
TestCase expectedTc = new TestCase();
expectedTc.setCaseId(2);
Expand All @@ -154,35 +154,35 @@ void getTestParametersByTestId() {
expectedTc.setAutomated(true);
expectedTc.setSummary("Test summary");
expectedTc.setArguments("");

//Get result from the "api"
TestCase resultingTc = spy.getTestCaseById(2);

// Resulting TestCase should be the same as in JSON response
assertThat(resultingTc, Matchers.samePropertyValuesAs(expectedTc));
}

@Test
void getTestParametersByTestIdWithEmptyResponse() {
RpcClient spy = Mockito.spy(new RpcClient());

//Empty response for getTestCaseById
JSONArray result = new JSONArray();
Mockito.doReturn(result).when((BaseRpcClient) spy).executeViaPositionalParams(eq(TEST_CASE_FILTER), anyList());

assertThat(spy.getTestCaseById(1), is(nullValue()));
}

@Test
void getTestParametersByTestIdWithEmptyObject() {
RpcClient spy = Mockito.spy(new RpcClient());

//Empty response for getTestCaseById
JSONArray result = new JSONArray();
JSONObject emptyCase = new JSONObject();
result.add(emptyCase);
Mockito.doReturn(result).when((BaseRpcClient) spy).executeViaPositionalParams(eq(TEST_CASE_FILTER), anyList());

assertThat(spy.getTestCaseById(1), is(nullValue()));
}
}

0 comments on commit f2c0282

Please sign in to comment.