From f2c028296bce86e126385785062af74621d4583f Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 30 Aug 2023 16:53:10 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- README.md | 4 +- ...TcmsTestAttributesAnnotationProcessor.java | 12 +++--- .../java/org/kiwitcms/java/api/RpcClient.java | 38 +++++++++---------- .../java/org/kiwitcms/java/config/Config.java | 2 +- .../java/junit/KiwiTcmsExtension.java | 4 +- .../kiwitcms/java/junit/TestDataEmitter.java | 6 +-- .../org/kiwitcms/java/api/TestingRpcTest.java | 28 +++++++------- 7 files changed, 47 insertions(+), 47 deletions(-) diff --git a/README.md b/README.md index 71ee05a..ed64d24 100644 --- a/README.md +++ b/README.md @@ -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` diff --git a/src/main/java/org/kiwitcms/java/annotations/TcmsTestAttributesAnnotationProcessor.java b/src/main/java/org/kiwitcms/java/annotations/TcmsTestAttributesAnnotationProcessor.java index 03c1fa4..f953aa5 100644 --- a/src/main/java/org/kiwitcms/java/annotations/TcmsTestAttributesAnnotationProcessor.java +++ b/src/main/java/org/kiwitcms/java/annotations/TcmsTestAttributesAnnotationProcessor.java @@ -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; - + public TcmsTestAttributesAnnotationProcessor(Class annotatedClass) { if (annotatedClass.isAnnotationPresent(TcmsTestAttributes.class)) { TcmsTestAttributes classAttributes = annotatedClass.getAnnotation(TcmsTestAttributes.class); @@ -18,7 +18,7 @@ public TcmsTestAttributesAnnotationProcessor(Class annotatedClass) { this.planId = classAttributes.planId(); } } - + public TcmsTestAttributesAnnotationProcessor(Method annotatedMethod) { if (annotatedMethod.isAnnotationPresent(TcmsTestAttributes.class)) { TcmsTestAttributes methodAttributes = annotatedMethod.getAnnotation(TcmsTestAttributes.class); @@ -28,16 +28,16 @@ public TcmsTestAttributesAnnotationProcessor(Method annotatedMethod) { this.planId = methodAttributes.planId(); } } - + public int getTestCaseId() { if (this.testCaseId > 0) {return this.testCaseId;} return Math.max(this.value, 0); } - + public int getProductId() { return Math.max(this.productId, 0); } - + public int getPlanId() { return Math.max(this.planId, 0); } diff --git a/src/main/java/org/kiwitcms/java/api/RpcClient.java b/src/main/java/org/kiwitcms/java/api/RpcClient.java index 5beda08..347625a 100644 --- a/src/main/java/org/kiwitcms/java/api/RpcClient.java +++ b/src/main/java/org/kiwitcms/java/api/RpcClient.java @@ -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 params = new HashMap<>(); @@ -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)); @@ -134,7 +134,7 @@ public TestCase[] getRunIdTestCases(int runId) { return new TestCase[0]; } } - + //TODO: test coverage public TestExecution[] addTestCaseToRunId(int runId, int caseId) { Map params = new HashMap<>(); @@ -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 filter = new HashMap<>(); @@ -202,7 +202,7 @@ public TestRun getRun(int runId) { } } } - + //TODO: test coverage public TestPlan createNewTP(int productId, String name, int versionId) { Map params = new HashMap<>(); @@ -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 filter = new HashMap<>(); @@ -252,7 +252,7 @@ public TestExecution getTestExecution(Map filter) { } } } - + //TODO: test coverage public TestExecution updateTestExecution(int tcRunId, int status) { Map values = new HashMap<>(); @@ -277,7 +277,7 @@ public JSONArray getTestCaseStatus(Map filter) { JSONArray jsonArray = (JSONArray) executeViaPositionalParams(TEST_CASE_STATUS_FILTER, Arrays.asList((Object) filter)); return jsonArray; } - + //TODO: test coverage //Get first available public int getConfirmedTCStatusId() { @@ -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 filter = new HashMap<>(); @@ -304,7 +304,7 @@ public Integer getProductId(String name) { } } } - + //TODO: test coverage public Product createNewProduct(String name) { Map params = new HashMap<>(); @@ -325,7 +325,7 @@ public Product createNewProduct(String name) { return null; } } - + //TODO: test coverage public Build[] getBuilds(Map filter) { JSONArray jsonArray = (JSONArray) executeViaPositionalParams(BUILD_FILTER, Arrays.asList((Object) filter)); @@ -341,7 +341,7 @@ public Build[] getBuilds(Map filter) { } } } - + //TODO: test coverage public Build createBuild(String name, int versionId) { Map params = new HashMap<>(); @@ -355,7 +355,7 @@ public Build createBuild(String name, int versionId) { return null; } } - + //TODO: test coverage public Version[] getVersions(Map filter) { JSONArray jsonArray = (JSONArray) executeViaPositionalParams(VERSION_FILTER, Arrays.asList((Object) filter)); @@ -371,7 +371,7 @@ public Version[] getVersions(Map filter) { } } } - + //TODO: test coverage public Version createProductVersion(String version, int productId) { Map params = new HashMap<>(); @@ -386,7 +386,7 @@ public Version createProductVersion(String version, int productId) { return null; } } - + //TODO: test coverage public Priority[] getPriority(Map filter) { JSONArray jsonArray = (JSONArray) executeViaPositionalParams(PRIORITY_FILTER, Arrays.asList((Object) filter)); @@ -401,13 +401,13 @@ public Priority[] getPriority(Map filter) { } } } - + //TODO: test coverage // TODO: Create Category class public JSONArray getCategory(Map filter) { return (JSONArray) executeViaPositionalParams(CATEGORY_FILTER, Arrays.asList((Object) filter)); } - + //TODO: test coverage public TestExecutionStatus getTestExecutionStatus(String name, String weightLookup) { Map filter = new HashMap<>(); @@ -430,7 +430,7 @@ public TestExecutionStatus getTestExecutionStatus(String name, String weightLook return null; } } - + public TestCase getTestCaseById(int testCaseId) { Map filter = new HashMap<>(); filter.put("id", testCaseId); @@ -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]; diff --git a/src/main/java/org/kiwitcms/java/config/Config.java b/src/main/java/org/kiwitcms/java/config/Config.java index 7a88f36..08839f9 100644 --- a/src/main/java/org/kiwitcms/java/config/Config.java +++ b/src/main/java/org/kiwitcms/java/config/Config.java @@ -87,7 +87,7 @@ public String getBuild() { orElse(Optional.ofNullable(System.getenv("BUILD_NUMBER")). orElse(config.node("tcms").get("build", null)))); } - + public String getRunName() { return Optional.ofNullable(System.getProperty("tcmsRunName")). orElse(config.node("tcms").get("runName", null)); diff --git a/src/main/java/org/kiwitcms/java/junit/KiwiTcmsExtension.java b/src/main/java/org/kiwitcms/java/junit/KiwiTcmsExtension.java index 7fe3d6c..99717d3 100644 --- a/src/main/java/org/kiwitcms/java/junit/KiwiTcmsExtension.java +++ b/src/main/java/org/kiwitcms/java/junit/KiwiTcmsExtension.java @@ -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); @@ -66,7 +66,7 @@ public void afterEach(ExtensionContext context) { if (classAnnotation.getPlanId() != 0 && methodAnnotation.getPlanId() != 0 && classAnnotation.getPlanId() != methodAnnotation.getPlanId()) { test.testPlanId = methodAnnotation.getPlanId(); } - + tests.add(test); } } diff --git a/src/main/java/org/kiwitcms/java/junit/TestDataEmitter.java b/src/main/java/org/kiwitcms/java/junit/TestDataEmitter.java index 345e232..380f065 100644 --- a/src/main/java/org/kiwitcms/java/junit/TestDataEmitter.java +++ b/src/main/java/org/kiwitcms/java/junit/TestDataEmitter.java @@ -107,16 +107,16 @@ public void addTestResultsToRun(int runId, List 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); } if (ObjectUtils.isEmpty(testCase)) { testCase = client.getOrCreateTestCase(overrideProductId, categoryId, priorityId, test.getSummary()); } - + client.addTestCaseToPlan(overridePlanId, testCase.getCaseId()); - + TestExecution[] executions = client.addTestCaseToRunId(runId, testCase.getCaseId()); for (TestExecution testExecution : executions) { client.updateTestExecution(testExecution.getTcRunId(), getTestExecutionStatusId(test.result)); diff --git a/src/test/java/org/kiwitcms/java/api/TestingRpcTest.java b/src/test/java/org/kiwitcms/java/api/TestingRpcTest.java index 24fce34..b81c8a8 100644 --- a/src/test/java/org/kiwitcms/java/api/TestingRpcTest.java +++ b/src/test/java/org/kiwitcms/java/api/TestingRpcTest.java @@ -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(); @@ -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); @@ -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())); } }