├── .DS_Store ├── .gitignore ├── LICENSE.md ├── README.md ├── logo.png ├── pnx-test-bom └── pom.xml ├── pnx-test-dependencies └── pom.xml ├── pnx-test-starter-core ├── .DS_Store ├── .gitignore ├── pom.xml └── src │ ├── main │ ├── .DS_Store │ ├── java │ │ └── com │ │ │ └── pnxtest │ │ │ └── core │ │ │ ├── AppInfo.java │ │ │ ├── ApplicationKeys.java │ │ │ ├── CmdParser.java │ │ │ ├── DefaultCrypto.java │ │ │ ├── PnxTest.java │ │ │ ├── api │ │ │ ├── AfterAll.java │ │ │ ├── AfterEach.java │ │ │ ├── BeforeAll.java │ │ │ ├── BeforeEach.java │ │ │ ├── Configuration.java │ │ │ ├── Controller.java │ │ │ ├── DataDriven.java │ │ │ ├── Description.java │ │ │ ├── Disabled.java │ │ │ ├── DisplayName.java │ │ │ ├── ICryptoConfig.java │ │ │ ├── IExecutionConfig.java │ │ │ ├── IModConfig.java │ │ │ ├── Issue.java │ │ │ ├── Level.java │ │ │ ├── Levels.java │ │ │ ├── Order.java │ │ │ ├── PnxTestApplication.java │ │ │ ├── RepeatedCount.java │ │ │ ├── Repository.java │ │ │ ├── Status.java │ │ │ └── Test.java │ │ │ ├── assertions │ │ │ ├── AbstractArrayAssert.java │ │ │ ├── AbstractBaseAssert.java │ │ │ ├── AbstractCollectionAssert.java │ │ │ ├── AbstractComparableAssert.java │ │ │ ├── AbstractEnumerableAssert.java │ │ │ ├── BigDecimalAssert.java │ │ │ ├── BooleanAssert.java │ │ │ ├── ByteArrayAssert.java │ │ │ ├── ByteAssert.java │ │ │ ├── CharArrayAssert.java │ │ │ ├── CharAssert.java │ │ │ ├── CollectionAssert.java │ │ │ ├── DoubleArrayAssert.java │ │ │ ├── DoubleAssert.java │ │ │ ├── FileAssert.java │ │ │ ├── FloatArrayAssert.java │ │ │ ├── FloatAssert.java │ │ │ ├── IntegerArrayAssert.java │ │ │ ├── IntegerAssert.java │ │ │ ├── ListAssert.java │ │ │ ├── LongArrayAssert.java │ │ │ ├── LongAssert.java │ │ │ ├── MapAssert.java │ │ │ ├── ObjectArrayAssert.java │ │ │ ├── ObjectAssert.java │ │ │ ├── PnxAssert.java │ │ │ ├── SetAssert.java │ │ │ ├── ShortArrayAssert.java │ │ │ ├── ShortAssert.java │ │ │ ├── StringArrayAssert.java │ │ │ ├── StringAssert.java │ │ │ └── TextDescription.java │ │ │ ├── environment │ │ │ ├── Environment.java │ │ │ ├── PnxContext.java │ │ │ ├── Property.java │ │ │ └── VariableResolver.java │ │ │ ├── exceptions │ │ │ ├── CmdArgsParseException.java │ │ │ ├── DataProviderException.java │ │ │ ├── PnxException.java │ │ │ ├── PnxModuleException.java │ │ │ ├── SkipException.java │ │ │ └── StepException.java │ │ │ ├── executors │ │ │ ├── AbstractBaseResult.java │ │ │ ├── Acronym.java │ │ │ ├── ClassResult.java │ │ │ ├── CurrentTestInfo.java │ │ │ ├── DataProviderLog.java │ │ │ ├── IExecutor.java │ │ │ ├── MethodResult.java │ │ │ ├── RepetitionLog.java │ │ │ ├── ResultCollector.java │ │ │ ├── RunResult.java │ │ │ ├── Task.java │ │ │ ├── TestCase.java │ │ │ ├── TestCaseTask.java │ │ │ ├── TestClass.java │ │ │ ├── TestClassExecutor.java │ │ │ ├── TestClassTask.java │ │ │ ├── TestMethodExecutor.java │ │ │ ├── TestRun.java │ │ │ ├── TestRunExecutor.java │ │ │ ├── TestRunTask.java │ │ │ └── TestSuite.java │ │ │ ├── helper │ │ │ └── PnxHelper.java │ │ │ ├── outputting │ │ │ ├── ConsoleLog.java │ │ │ ├── HtmlLog.java │ │ │ ├── StatsInfo.java │ │ │ ├── StepTree.java │ │ │ ├── TestCaseInfo.java │ │ │ ├── TestRunInfo.java │ │ │ └── TestSuiteInfo.java │ │ │ ├── steps │ │ │ ├── PnxSteps.java │ │ │ ├── Step.java │ │ │ ├── StepInterceptor.java │ │ │ ├── StepLog.java │ │ │ ├── StepLogger.java │ │ │ ├── StepMessage.java │ │ │ ├── Steps.java │ │ │ ├── StepsFactory.java │ │ │ ├── StepsField.java │ │ │ ├── StepsInjector.java │ │ │ └── StepsModule.java │ │ │ └── util │ │ │ ├── ClassUtil.java │ │ │ ├── CsvReader.java │ │ │ ├── DateUtil.java │ │ │ ├── ExceptionUtil.java │ │ │ ├── FileUtil.java │ │ │ ├── MethodUtil.java │ │ │ └── StringUtil.java │ └── resources │ │ └── pnxtest.xsd │ └── test │ └── java │ └── cn │ └── pnxtestframework │ └── .DS_Store ├── pnx-test-starter-db ├── .gitignore ├── pom.xml └── src │ └── main │ ├── antlr4 │ └── lexer │ │ ├── ColonStatementLexer.g4 │ │ └── DefineStatementLexer.g4 │ └── java │ └── com │ └── pnxtest │ └── db │ ├── DbConfig.java │ ├── PnxSql.java │ ├── api │ ├── BatchQuery.java │ ├── Column.java │ ├── Entity.java │ ├── Query.java │ ├── SelectQuery.java │ └── UpdateQuery.java │ └── internal │ ├── BaseQuery.java │ ├── BatchQueryImpl.java │ ├── ConnectionFactory.java │ ├── DeleteQueryImpl.java │ ├── InsertQueryImpl.java │ ├── ParsedParameters.java │ ├── ParsedSql.java │ ├── PnxSqlException.java │ ├── SelectQueryImpl.java │ └── UpdateQueryImpl.java ├── pnx-test-starter-http ├── .gitignore ├── pom.xml └── src │ └── main │ └── java │ └── com │ └── pnxtest │ └── http │ ├── HttpConfig.java │ ├── PnxHttp.java │ ├── api │ ├── Body.java │ ├── Client.java │ ├── GetRequest.java │ ├── Header.java │ ├── HttpRequest.java │ ├── HttpRequestWithBody.java │ ├── HttpResponse.java │ ├── IHttpConfig.java │ ├── MultipartBody.java │ ├── ObjectMapper.java │ ├── RawResponse.java │ ├── RequestBodyEntity.java │ ├── RequestInterceptor.java │ └── ResponseInterceptor.java │ └── internal │ ├── ApacheBodyMapper.java │ ├── ApacheClient.java │ ├── ApacheDeleteWithBody.java │ ├── ApacheNoRedirectStrategy.java │ ├── ApachePatchWithBody.java │ ├── ApacheRequestWithBody.java │ ├── ApacheResponse.java │ ├── BaseApacheClient.java │ ├── BaseRequest.java │ ├── BaseResponse.java │ ├── BasicResponse.java │ ├── BodyPart.java │ ├── BodyString.java │ ├── ByteArrayBody.java │ ├── ByteArrayPart.java │ ├── ContentType.java │ ├── Empty.java │ ├── EmptyResponse.java │ ├── FilePart.java │ ├── FileResponse.java │ ├── GenericType.java │ ├── HeaderNames.java │ ├── Headers.java │ ├── HttpConfigException.java │ ├── HttpException.java │ ├── HttpGateway.java │ ├── HttpMethod.java │ ├── HttpParsingException.java │ ├── HttpRequestBodyRaw.java │ ├── HttpRequestImplWithBody.java │ ├── HttpRequestImplWithoutBody.java │ ├── HttpRequestMultiPart.java │ ├── HttpUtil.java │ ├── InputStreamPart.java │ ├── JacksonObjectMapper.java │ ├── MappedResponse.java │ ├── MultipartMode.java │ ├── ObjectResponse.java │ ├── ParamPart.java │ ├── Path.java │ ├── PreparedRequest.java │ ├── Proxy.java │ ├── RawResponseBase.java │ ├── RequestOptions.java │ ├── SecurityConfig.java │ ├── SimpleResponse.java │ ├── StreamBody.java │ ├── StringResponse.java │ └── SyncIdleConnectionMonitorThread.java ├── pnx-test-starter-parent └── pom.xml └── pom.xml /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pengtech/pnxtest/ac2dd0fe1cb12a32845a5348cb50e146952f0f11/.DS_Store -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | #Intellij project files 2 | .idea 3 | *.iml 4 | target 5 | integrationTest 6 | index-origin.html 7 | pnx-test-starter-syncloud 8 | test-config 9 | test-outputting 10 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | This program is offered under the AGPL license. 2 | 3 | AGPL licensing: 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU Affero General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU Affero General Public License for more details. 13 | 14 | You should have received a copy of the GNU Affero General Public License 15 | along with this program. If not, see . -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PnxTest 2 | pnxtest-logo 3 | PnxTest is a Java-based test automation framework that unites all testing layers: Mobile applications, WEB applications, REST services. 4 | Due to fluent API design and rich ecosystem applications, PnxTest will make your automation test more efficient. 5 | 6 | **Current release version**: 1.0.2 7 | 8 | **User guide:** https://pnxtest.com/user-guide 9 | 10 | **Online Report Reference**: https://pnxtest.com/user-guide/demo/reporting.html 11 | 12 | **Demo/Scaffolding Project**: https://github.com/pengtech/integrationTest 13 | 14 | **Maven dependency:** 15 | 16 | ```xml 17 | 18 | 19 | pnx-test-starter-parent 20 | com.pnxtest 21 | 1.0.2 22 | 23 | 24 | 25 | 26 | 27 | com.pnxtest 28 | pnx-test-starter-core 29 | 30 | 31 | 32 | com.pnxtest 33 | pnx-test-starter-http 34 | 35 | 36 | 37 | com.pnxtest 38 | pnx-test-starter-db 39 | 40 | 41 | mysql 42 | mysql-connector-java 43 | 44 | 45 | ``` 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pengtech/pnxtest/ac2dd0fe1cb12a32845a5348cb50e146952f0f11/logo.png -------------------------------------------------------------------------------- /pnx-test-bom/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 22 | 23 | 25 | 4.0.0 26 | 27 | 28 | com.pnxtest 29 | pnx-test-projects 30 | 1.0.2 31 | 32 | 33 | pnx-test-bom 34 | pom 35 | pnx-test-bom 36 | Bill of materials to make sure a consistent set of versions is used for pnxtest modules 37 | 38 | 39 | 40 | 41 | com.pnxtest 42 | pnx-test-starter-core 43 | 1.0.2 44 | 45 | 46 | com.pnxtest 47 | pnx-test-starter-http 48 | 1.0.2 49 | 50 | 51 | com.pnxtest 52 | pnx-test-starter-db 53 | 1.0.2 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /pnx-test-starter-core/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pengtech/pnxtest/ac2dd0fe1cb12a32845a5348cb50e146952f0f11/pnx-test-starter-core/.DS_Store -------------------------------------------------------------------------------- /pnx-test-starter-core/.gitignore: -------------------------------------------------------------------------------- 1 | #Intellij project files 2 | .idea 3 | *.iml 4 | target 5 | 6 | -------------------------------------------------------------------------------- /pnx-test-starter-core/src/main/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pengtech/pnxtest/ac2dd0fe1cb12a32845a5348cb50e146952f0f11/pnx-test-starter-core/src/main/.DS_Store -------------------------------------------------------------------------------- /pnx-test-starter-core/src/main/java/com/pnxtest/core/AppInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.core; 23 | 24 | public class AppInfo { 25 | public static final String version="1.0.2"; 26 | public static final String name="PnxTest"; 27 | public static final String owner="PNX"; 28 | public static final String author="nicolas.chen"; 29 | public static final String url="https://pnxtest.com"; 30 | } 31 | -------------------------------------------------------------------------------- /pnx-test-starter-core/src/main/java/com/pnxtest/core/ApplicationKeys.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.core; 23 | 24 | import java.util.ArrayList; 25 | import java.util.List; 26 | 27 | public final class ApplicationKeys { 28 | public static final String PNX_RUN_MODE = "pnx.run.mode"; 29 | public static final String PNX_THREAD_COUNT = "pnx.thread.count"; 30 | public static final String PNX_TARGET_FILE = "pnx.target.file"; 31 | public static final String PNX_ENVIRONMENT_ID = "pnx.environment.id"; 32 | public static final String PNX_ENVIRONMENT_PATH = "pnx.environment.path"; 33 | public static final String PNX_CRYPTO_IMPL = "pnx.crypto.impl"; 34 | public static final String PNX_OUTPUTTING_PATH = "pnx.outputting.path"; 35 | public static final String PNX_CURRENT_METHOD_NAME = "pnx.current.method.name"; 36 | public static final String PNX_CURRENT_STEP_NAME = "pnx.current.step.name"; 37 | 38 | public static final String PNX_MODULE_CONFIG_BEANS = "pnx.module.config.beans"; 39 | 40 | 41 | 42 | public static List listAll(){ 43 | List allKeys = new ArrayList<>(); 44 | allKeys.add(PNX_RUN_MODE); 45 | allKeys.add(PNX_THREAD_COUNT); 46 | allKeys.add(PNX_TARGET_FILE); 47 | allKeys.add(PNX_ENVIRONMENT_ID); 48 | allKeys.add(PNX_ENVIRONMENT_PATH); 49 | allKeys.add(PNX_CRYPTO_IMPL); 50 | allKeys.add(PNX_OUTPUTTING_PATH); 51 | allKeys.add(PNX_CURRENT_METHOD_NAME); 52 | allKeys.add(PNX_CURRENT_STEP_NAME); 53 | allKeys.add(PNX_MODULE_CONFIG_BEANS); 54 | 55 | return allKeys; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /pnx-test-starter-core/src/main/java/com/pnxtest/core/DefaultCrypto.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.core; 23 | 24 | import com.pnxtest.core.api.ICryptoConfig; 25 | import com.pnxtest.core.util.StringUtil; 26 | 27 | class DefaultCrypto implements ICryptoConfig { 28 | 29 | DefaultCrypto(){ 30 | 31 | } 32 | 33 | public String decrypt(String cipherText){ 34 | if(StringUtil.isEmpty(cipherText)) return ""; 35 | StringBuilder sb = new StringBuilder(); 36 | int len = cipherText.length(); 37 | for(int i=0; i. 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.core.api; 23 | 24 | import java.lang.annotation.*; 25 | 26 | @Target(ElementType.METHOD) 27 | @Retention(RetentionPolicy.RUNTIME) 28 | @Documented 29 | public @interface AfterAll { 30 | 31 | } 32 | -------------------------------------------------------------------------------- /pnx-test-starter-core/src/main/java/com/pnxtest/core/api/AfterEach.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.core.api; 23 | 24 | import java.lang.annotation.*; 25 | 26 | @Target(ElementType.METHOD) 27 | @Retention(RetentionPolicy.RUNTIME) 28 | @Documented 29 | public @interface AfterEach { 30 | } 31 | -------------------------------------------------------------------------------- /pnx-test-starter-core/src/main/java/com/pnxtest/core/api/BeforeAll.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.core.api; 23 | 24 | import java.lang.annotation.*; 25 | 26 | @Target(ElementType.METHOD) 27 | @Retention(RetentionPolicy.RUNTIME) 28 | @Documented 29 | public @interface BeforeAll { 30 | 31 | } 32 | -------------------------------------------------------------------------------- /pnx-test-starter-core/src/main/java/com/pnxtest/core/api/BeforeEach.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.core.api; 23 | 24 | import java.lang.annotation.*; 25 | 26 | @Target(ElementType.METHOD) 27 | @Retention(RetentionPolicy.RUNTIME) 28 | @Documented 29 | public @interface BeforeEach { 30 | 31 | } 32 | -------------------------------------------------------------------------------- /pnx-test-starter-core/src/main/java/com/pnxtest/core/api/Configuration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.core.api; 23 | 24 | import java.lang.annotation.*; 25 | 26 | @Target({ElementType.TYPE}) 27 | @Retention(RetentionPolicy.RUNTIME) 28 | @Documented 29 | public @interface Configuration { 30 | } 31 | -------------------------------------------------------------------------------- /pnx-test-starter-core/src/main/java/com/pnxtest/core/api/Controller.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.core.api; 23 | 24 | import java.lang.annotation.*; 25 | 26 | @Target({ ElementType.TYPE }) 27 | @Retention(RetentionPolicy.RUNTIME) 28 | @Documented 29 | public @interface Controller { 30 | String module(); 31 | String maintainer() default ""; 32 | } 33 | -------------------------------------------------------------------------------- /pnx-test-starter-core/src/main/java/com/pnxtest/core/api/DataDriven.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.core.api; 23 | 24 | 25 | import java.lang.annotation.*; 26 | 27 | @Target(ElementType.METHOD) 28 | @Retention(RetentionPolicy.RUNTIME) 29 | @Documented 30 | public @interface DataDriven { 31 | 32 | String value(); //data source 33 | String type() default "file"; //file, string 34 | 35 | String encoding() default "UTF-8"; 36 | String lineSeparator() default "\n"; 37 | char separator() default ','; 38 | boolean withHeader() default false; 39 | //boolean parallel() default false; 40 | } 41 | -------------------------------------------------------------------------------- /pnx-test-starter-core/src/main/java/com/pnxtest/core/api/Description.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.core.api; 23 | 24 | import java.lang.annotation.*; 25 | 26 | @Target(ElementType.METHOD) 27 | @Retention(RetentionPolicy.RUNTIME) 28 | @Documented 29 | public @interface Description { 30 | String value(); 31 | } 32 | -------------------------------------------------------------------------------- /pnx-test-starter-core/src/main/java/com/pnxtest/core/api/Disabled.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.core.api; 23 | 24 | import java.lang.annotation.*; 25 | 26 | @Target({ ElementType.TYPE, ElementType.METHOD }) 27 | @Retention(RetentionPolicy.RUNTIME) 28 | @Documented 29 | public @interface Disabled { 30 | String value() default ""; //reason of a class or method is disabled 31 | } 32 | -------------------------------------------------------------------------------- /pnx-test-starter-core/src/main/java/com/pnxtest/core/api/DisplayName.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.core.api; 23 | 24 | import java.lang.annotation.*; 25 | 26 | @Target(ElementType.METHOD) 27 | @Retention(RetentionPolicy.RUNTIME) 28 | @Documented 29 | public @interface DisplayName { 30 | String value(); 31 | } 32 | -------------------------------------------------------------------------------- /pnx-test-starter-core/src/main/java/com/pnxtest/core/api/ICryptoConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.core.api; 23 | 24 | public interface ICryptoConfig { 25 | String decrypt(String cipherText); 26 | String encrypt(String plainText); 27 | } 28 | -------------------------------------------------------------------------------- /pnx-test-starter-core/src/main/java/com/pnxtest/core/api/IExecutionConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.core.api; 23 | 24 | public interface IExecutionConfig { 25 | 26 | void onExecuteStart(); 27 | void onExecuteFinish(); 28 | 29 | } 30 | -------------------------------------------------------------------------------- /pnx-test-starter-core/src/main/java/com/pnxtest/core/api/IModConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.core.api; 23 | 24 | public interface IModConfig { 25 | } 26 | -------------------------------------------------------------------------------- /pnx-test-starter-core/src/main/java/com/pnxtest/core/api/Issue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.core.api; 23 | 24 | import java.lang.annotation.*; 25 | 26 | @Target(ElementType.METHOD) 27 | @Retention(RetentionPolicy.RUNTIME) 28 | @Documented 29 | public @interface Issue { 30 | String[] value(); 31 | } 32 | -------------------------------------------------------------------------------- /pnx-test-starter-core/src/main/java/com/pnxtest/core/api/Level.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.core.api; 23 | 24 | import java.lang.annotation.*; 25 | 26 | @Target(ElementType.METHOD) 27 | @Retention(RetentionPolicy.RUNTIME) 28 | @Documented 29 | public @interface Level { 30 | Levels value(); 31 | } 32 | -------------------------------------------------------------------------------- /pnx-test-starter-core/src/main/java/com/pnxtest/core/api/Levels.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.core.api; 23 | 24 | public enum Levels { 25 | L1, L2, L3, L4 26 | } 27 | -------------------------------------------------------------------------------- /pnx-test-starter-core/src/main/java/com/pnxtest/core/api/Order.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.core.api; 23 | 24 | import java.lang.annotation.ElementType; 25 | import java.lang.annotation.Retention; 26 | import java.lang.annotation.RetentionPolicy; 27 | import java.lang.annotation.Target; 28 | 29 | @Target(ElementType.METHOD) 30 | @Retention(RetentionPolicy.RUNTIME) 31 | public @interface Order { 32 | int value(); 33 | } 34 | -------------------------------------------------------------------------------- /pnx-test-starter-core/src/main/java/com/pnxtest/core/api/PnxTestApplication.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.core.api; 23 | 24 | import java.lang.annotation.*; 25 | 26 | @Target({ ElementType.TYPE }) 27 | @Retention(RetentionPolicy.RUNTIME) 28 | @Documented 29 | public @interface PnxTestApplication { 30 | String envID() default ""; //for IDE debug 31 | String suiteFile() default ""; //for IDE debug 32 | 33 | } 34 | -------------------------------------------------------------------------------- /pnx-test-starter-core/src/main/java/com/pnxtest/core/api/RepeatedCount.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.core.api; 23 | 24 | import java.lang.annotation.*; 25 | 26 | @Target(ElementType.METHOD) 27 | @Retention(RetentionPolicy.RUNTIME) 28 | @Documented 29 | public @interface RepeatedCount { 30 | int value(); 31 | float successPercentage() default 100.00f; 32 | } 33 | -------------------------------------------------------------------------------- /pnx-test-starter-core/src/main/java/com/pnxtest/core/api/Repository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.core.api; 23 | 24 | import java.lang.annotation.*; 25 | 26 | @Target({ ElementType.TYPE }) 27 | @Retention(RetentionPolicy.RUNTIME) 28 | @Documented 29 | public @interface Repository { 30 | } 31 | -------------------------------------------------------------------------------- /pnx-test-starter-core/src/main/java/com/pnxtest/core/api/Status.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.core.api; 23 | 24 | public enum Status { 25 | PASSED(1), 26 | FAILED(2), 27 | SKIPPED(3), 28 | BLOCKED(4), 29 | NT(0); 30 | 31 | private final int value; 32 | Status(int value){ 33 | this.value = value; 34 | } 35 | 36 | public int getValue() { 37 | return value; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /pnx-test-starter-core/src/main/java/com/pnxtest/core/api/Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.core.api; 23 | 24 | import java.lang.annotation.*; 25 | 26 | 27 | /** 28 | * the definition of a testcase 29 | * @author nicolas.chen 30 | */ 31 | 32 | @Target({ElementType.METHOD}) 33 | @Retention(RetentionPolicy.RUNTIME) 34 | @Documented 35 | public @interface Test { 36 | 37 | } 38 | -------------------------------------------------------------------------------- /pnx-test-starter-core/src/main/java/com/pnxtest/core/assertions/AbstractComparableAssert.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.core.assertions; 23 | 24 | import org.hamcrest.Matchers; 25 | 26 | /** 27 | * comparable assertions 28 | * @param 29 | * @param 30 | */ 31 | public abstract class AbstractComparableAssert> extends AbstractBaseAssert{ 32 | public AbstractComparableAssert(A actual, Class myself){ 33 | super(actual, myself); 34 | } 35 | 36 | 37 | public S isGreaterThan(A other){ 38 | setKeywords("isGreaterThan"); 39 | assertThat(Matchers.greaterThan(other)); 40 | return myself; 41 | } 42 | 43 | public S isGreaterThanOrEqualTo(A other){ 44 | setKeywords("isGreaterThanOrEqualTo"); 45 | assertThat(Matchers.greaterThanOrEqualTo(other)); 46 | return myself; 47 | } 48 | 49 | public S isLessThan(A other){ 50 | setKeywords("isLessThan"); 51 | assertThat(Matchers.lessThan(other)); 52 | return myself; 53 | } 54 | 55 | public S isLessThanOrEqualTo(A other){ 56 | setKeywords("lessThanOrEqualTo"); 57 | assertThat(Matchers.lessThanOrEqualTo(other)); 58 | return myself; 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /pnx-test-starter-core/src/main/java/com/pnxtest/core/assertions/BigDecimalAssert.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.core.assertions; 23 | 24 | import org.hamcrest.Matchers; 25 | 26 | import java.math.BigDecimal; 27 | 28 | public class BigDecimalAssert extends AbstractComparableAssert { 29 | 30 | public BigDecimalAssert(BigDecimal actual) { 31 | super(actual, BigDecimalAssert.class); 32 | } 33 | 34 | 35 | public BigDecimalAssert isCloseTo(BigDecimal expected, BigDecimal delta) { 36 | setKeywords("bigDecimalIsCloseTo"); 37 | assertThat(Matchers.closeTo(expected, delta)); 38 | return this; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /pnx-test-starter-core/src/main/java/com/pnxtest/core/assertions/BooleanAssert.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.core.assertions; 23 | 24 | import org.hamcrest.Matchers; 25 | 26 | /** 27 | * Boolean Assertion 28 | * 29 | */ 30 | public class BooleanAssert extends AbstractBaseAssert{ 31 | 32 | BooleanAssert(boolean actual){ 33 | super(actual, BooleanAssert.class); 34 | } 35 | 36 | public BooleanAssert isTrue(){ 37 | setKeywords("isTrue"); 38 | assertThat(Matchers.equalTo(true)); 39 | return this; 40 | } 41 | 42 | public BooleanAssert isFalse(){ 43 | setKeywords("isFalse"); 44 | assertThat(Matchers.equalTo(false)); 45 | return this; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /pnx-test-starter-core/src/main/java/com/pnxtest/core/assertions/ByteArrayAssert.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.core.assertions; 23 | 24 | public class ByteArrayAssert extends AbstractArrayAssert{ 25 | 26 | public ByteArrayAssert(Byte[] actual) { 27 | super(actual, ByteArrayAssert.class); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /pnx-test-starter-core/src/main/java/com/pnxtest/core/assertions/ByteAssert.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.core.assertions; 23 | 24 | public class ByteAssert extends AbstractComparableAssert{ 25 | public ByteAssert(Byte actual) { 26 | super(actual, ByteAssert.class); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /pnx-test-starter-core/src/main/java/com/pnxtest/core/assertions/CharArrayAssert.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.core.assertions; 23 | 24 | public class CharArrayAssert extends AbstractArrayAssert { 25 | 26 | 27 | public CharArrayAssert(Character[] actual) { 28 | super(actual, CharArrayAssert.class); 29 | } 30 | 31 | 32 | } 33 | -------------------------------------------------------------------------------- /pnx-test-starter-core/src/main/java/com/pnxtest/core/assertions/CharAssert.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.core.assertions; 23 | 24 | import org.hamcrest.Matchers; 25 | 26 | public class CharAssert extends AbstractBaseAssert{ 27 | private char actual; 28 | 29 | public CharAssert(char actual){ 30 | super(actual, CharAssert.class); 31 | this.actual = actual; 32 | } 33 | 34 | public CharAssert isUpperCase(){ 35 | setKeywords("isUpperCase"); 36 | assertThat(Character.isUpperCase(actual), Matchers.equalTo(true)); 37 | return this; 38 | } 39 | 40 | public CharAssert isLowerCase(){ 41 | setKeywords("isLowerCase"); 42 | assertThat(Character.isLowerCase(actual), Matchers.equalTo(true)); 43 | return this; 44 | } 45 | } -------------------------------------------------------------------------------- /pnx-test-starter-core/src/main/java/com/pnxtest/core/assertions/CollectionAssert.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.core.assertions; 23 | 24 | import java.util.Collection; 25 | 26 | public class CollectionAssert extends AbstractCollectionAssert> { 27 | 28 | 29 | CollectionAssert(Collection actual) { 30 | super(actual, CollectionAssert.class); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /pnx-test-starter-core/src/main/java/com/pnxtest/core/assertions/DoubleArrayAssert.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.core.assertions; 23 | 24 | public class DoubleArrayAssert extends AbstractArrayAssert{ 25 | 26 | public DoubleArrayAssert(Double[] actual) { 27 | super(actual, DoubleArrayAssert.class); 28 | } 29 | 30 | 31 | } 32 | -------------------------------------------------------------------------------- /pnx-test-starter-core/src/main/java/com/pnxtest/core/assertions/DoubleAssert.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.core.assertions; 23 | 24 | import org.hamcrest.Matchers; 25 | 26 | public class DoubleAssert extends AbstractComparableAssert{ 27 | 28 | public DoubleAssert(Double actual) { 29 | super(actual, DoubleAssert.class); 30 | } 31 | 32 | 33 | public DoubleAssert isCloseTo(double expected, double delta){ 34 | setKeywords("doubleIsCloseTo"); 35 | assertThat(Matchers.closeTo(expected, delta)); 36 | return this; 37 | } 38 | 39 | public DoubleAssert isCloseTo(Double expected, Double delta){ 40 | setKeywords("doubleIsCloseTo"); 41 | assertThat(Matchers.closeTo(expected, delta)); 42 | return this; 43 | } 44 | 45 | public DoubleAssert isNotANumber(){ 46 | setKeywords("doubleIsNotANumber"); 47 | assertThat(Matchers.notANumber()); 48 | return this; 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /pnx-test-starter-core/src/main/java/com/pnxtest/core/assertions/FileAssert.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.core.assertions; 23 | 24 | import org.hamcrest.Matchers; 25 | import org.hamcrest.io.FileMatchers; 26 | 27 | import java.io.File; 28 | 29 | public class FileAssert extends AbstractBaseAssert{ 30 | 31 | 32 | FileAssert(File actual) { 33 | super(actual, FileAssert.class); 34 | } 35 | 36 | public FileAssert isDirectory(){ 37 | setKeywords("isDirectory"); 38 | assertThat(FileMatchers.anExistingDirectory()); 39 | return this; 40 | } 41 | 42 | public FileAssert isFile(){ 43 | setKeywords("isFile"); 44 | assertThat(FileMatchers.anExistingFile()); 45 | return this; 46 | } 47 | 48 | public FileAssert isFileOrDirectory(){ 49 | setKeywords("IsFileOrDirectory"); 50 | assertThat(FileMatchers.anExistingFileOrDirectory()); 51 | return this; 52 | } 53 | 54 | public FileAssert isNamed(String fileName){ 55 | setKeywords("fileIsNamed"); 56 | assertThat(FileMatchers.aFileNamed(Matchers.equalTo(fileName))); 57 | return this; 58 | } 59 | 60 | public FileAssert hasSize(long fileSize){ 61 | setKeywords("fileHasSize"); 62 | assertThat(FileMatchers.aFileWithSize(fileSize)); 63 | return this; 64 | } 65 | 66 | 67 | 68 | } 69 | -------------------------------------------------------------------------------- /pnx-test-starter-core/src/main/java/com/pnxtest/core/assertions/FloatArrayAssert.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.core.assertions; 23 | 24 | public class FloatArrayAssert extends AbstractArrayAssert{ 25 | 26 | public FloatArrayAssert(Float[] actual) { 27 | super(actual, FloatArrayAssert.class); 28 | } 29 | 30 | 31 | } 32 | -------------------------------------------------------------------------------- /pnx-test-starter-core/src/main/java/com/pnxtest/core/assertions/FloatAssert.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.core.assertions; 23 | 24 | import org.hamcrest.Matchers; 25 | 26 | public class FloatAssert extends AbstractComparableAssert{ 27 | 28 | public FloatAssert(float actual) { 29 | super(actual, FloatAssert.class); 30 | } 31 | 32 | 33 | public FloatAssert isCloseTo(float expected, float delta){ 34 | setKeywords("floatIsCloseTo"); 35 | assertThat(Matchers.closeTo(expected, delta)); 36 | return this; 37 | } 38 | 39 | public FloatAssert isCloseTo(Float expected, Float delta){ 40 | setKeywords("floatIsCloseTo"); 41 | assertThat(Matchers.closeTo(expected, delta)); 42 | return this; 43 | } 44 | 45 | public FloatAssert isNotANumber(){ 46 | setKeywords("floatIsNotANumber"); 47 | assertThat(Matchers.notANumber()); 48 | return this; 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /pnx-test-starter-core/src/main/java/com/pnxtest/core/assertions/IntegerArrayAssert.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.core.assertions; 23 | 24 | public class IntegerArrayAssert extends AbstractArrayAssert{ 25 | 26 | public IntegerArrayAssert(Integer[] actual) { 27 | super(actual, IntegerArrayAssert.class); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /pnx-test-starter-core/src/main/java/com/pnxtest/core/assertions/IntegerAssert.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.core.assertions; 23 | 24 | public class IntegerAssert extends AbstractComparableAssert{ 25 | 26 | public IntegerAssert(Integer actual) { 27 | super(actual, IntegerAssert.class); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /pnx-test-starter-core/src/main/java/com/pnxtest/core/assertions/ListAssert.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.core.assertions; 23 | 24 | import java.util.List; 25 | 26 | public class ListAssert extends AbstractCollectionAssert>{ 27 | 28 | ListAssert(List actual) { 29 | super(actual, ListAssert.class); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /pnx-test-starter-core/src/main/java/com/pnxtest/core/assertions/LongArrayAssert.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.core.assertions; 23 | 24 | public class LongArrayAssert extends AbstractArrayAssert{ 25 | 26 | public LongArrayAssert(Long[] actual) { 27 | super(actual, LongArrayAssert.class); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /pnx-test-starter-core/src/main/java/com/pnxtest/core/assertions/LongAssert.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.core.assertions; 23 | 24 | public class LongAssert extends AbstractComparableAssert{ 25 | public LongAssert(long actual) { 26 | super(actual, LongAssert.class); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /pnx-test-starter-core/src/main/java/com/pnxtest/core/assertions/MapAssert.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.core.assertions; 23 | 24 | import java.util.Map; 25 | 26 | public class MapAssert extends AbstractEnumerableAssert>{ 27 | MapAssert(Map actual) { 28 | super(actual, MapAssert.class); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /pnx-test-starter-core/src/main/java/com/pnxtest/core/assertions/ObjectArrayAssert.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.core.assertions; 23 | 24 | class ObjectArrayAssert extends AbstractArrayAssert{ 25 | 26 | public ObjectArrayAssert(Object[] actual) { 27 | super(actual, ObjectArrayAssert.class); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /pnx-test-starter-core/src/main/java/com/pnxtest/core/assertions/ObjectAssert.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.core.assertions; 23 | 24 | import org.hamcrest.Matchers; 25 | 26 | public class ObjectAssert extends AbstractBaseAssert{ 27 | 28 | ObjectAssert(Object actual) { 29 | super(actual, ObjectAssert.class); 30 | } 31 | 32 | public ObjectAssert hasProperty(String propertyName){ 33 | setKeywords("objectHasProperty"); 34 | assertThat(Matchers.hasProperty(propertyName)); 35 | return this; 36 | } 37 | 38 | public ObjectAssert hasPropertyWithValue(String propertyName, E value){ 39 | setKeywords("objectHasPropertyWithValue"); 40 | assertThat(Matchers.hasProperty(propertyName, Matchers.equalTo(value))); 41 | return this; 42 | } 43 | 44 | 45 | 46 | } 47 | -------------------------------------------------------------------------------- /pnx-test-starter-core/src/main/java/com/pnxtest/core/assertions/SetAssert.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.core.assertions; 23 | 24 | import java.util.Set; 25 | 26 | public class SetAssert extends AbstractCollectionAssert>{ 27 | 28 | public SetAssert(Set actual) { 29 | super(actual, SetAssert.class); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /pnx-test-starter-core/src/main/java/com/pnxtest/core/assertions/ShortArrayAssert.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.core.assertions; 23 | 24 | public class ShortArrayAssert extends AbstractArrayAssert{ 25 | 26 | public ShortArrayAssert(Short[] actual) { 27 | super(actual, ShortArrayAssert.class); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /pnx-test-starter-core/src/main/java/com/pnxtest/core/assertions/ShortAssert.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.core.assertions; 23 | 24 | public class ShortAssert extends AbstractComparableAssert{ 25 | 26 | public ShortAssert(Short actual) { 27 | super(actual, ShortAssert.class); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /pnx-test-starter-core/src/main/java/com/pnxtest/core/assertions/StringArrayAssert.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.core.assertions; 23 | 24 | public class StringArrayAssert extends AbstractArrayAssert { 25 | 26 | public StringArrayAssert(String[] actual){ 27 | super(actual, StringArrayAssert.class); 28 | } 29 | 30 | 31 | } 32 | -------------------------------------------------------------------------------- /pnx-test-starter-core/src/main/java/com/pnxtest/core/assertions/TextDescription.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.core.assertions; 23 | 24 | import java.util.Objects; 25 | 26 | public final class TextDescription { 27 | private final String value; 28 | private final Object[] args; 29 | 30 | public TextDescription(String value, Object... args) { 31 | this.value = value == null ? "" : value; 32 | this.args = (args == null || args.length == 0) ? null : (Object[])args.clone(); 33 | } 34 | 35 | public String value() { 36 | if(value == null || value.isEmpty()) return null; 37 | if(args == null || args.length == 0){ 38 | return (value.replace("%", "%%")).replace("%%n", "%n"); //escape percent 39 | }else{ 40 | return String.format(this.value, this.args); 41 | } 42 | } 43 | 44 | public int hashCode() { 45 | return Objects.hash(new Object[]{this.value, this.args}); 46 | } 47 | 48 | public boolean equals(Object obj) { 49 | if (this == obj) { 50 | return true; 51 | } else if (obj == null) { 52 | return false; 53 | } else if (this.getClass() != obj.getClass()) { 54 | return false; 55 | } else { 56 | TextDescription other = (TextDescription)obj; 57 | return Objects.deepEquals(this.value, other.value) && java.util.Arrays.deepEquals(this.args, other.args); 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /pnx-test-starter-core/src/main/java/com/pnxtest/core/exceptions/CmdArgsParseException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.core.exceptions; 23 | 24 | public class CmdArgsParseException extends RuntimeException{ 25 | 26 | 27 | private static final long serialVersionUID = 7454074003048425394L; 28 | 29 | public CmdArgsParseException(String message){ 30 | super(message); 31 | } 32 | 33 | public CmdArgsParseException(String message, Throwable cause) { 34 | super(message, cause); 35 | } 36 | 37 | public CmdArgsParseException(Throwable cause) { 38 | super(cause); 39 | } 40 | 41 | 42 | } 43 | -------------------------------------------------------------------------------- /pnx-test-starter-core/src/main/java/com/pnxtest/core/exceptions/DataProviderException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.core.exceptions; 23 | 24 | public class DataProviderException extends RuntimeException{ 25 | private static final long serialVersionUID = -4935553156746662723L; 26 | public DataProviderException(String message){ 27 | super(message); 28 | } 29 | 30 | public DataProviderException(String message, Throwable cause) { 31 | super(message, cause); 32 | 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /pnx-test-starter-core/src/main/java/com/pnxtest/core/exceptions/PnxException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.core.exceptions; 23 | 24 | public class PnxException extends RuntimeException{ 25 | private static final long serialVersionUID = -3082300531471863907L; 26 | 27 | public PnxException(String message){ 28 | super(message); 29 | } 30 | 31 | public PnxException(String message, Throwable cause) { 32 | super(message, cause); 33 | } 34 | 35 | public PnxException(Throwable cause) { 36 | super(cause); 37 | } 38 | 39 | 40 | } 41 | -------------------------------------------------------------------------------- /pnx-test-starter-core/src/main/java/com/pnxtest/core/exceptions/PnxModuleException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.core.exceptions; 23 | 24 | public class PnxModuleException extends RuntimeException{ 25 | 26 | 27 | private static final long serialVersionUID = 6342609091196817888L; 28 | 29 | public PnxModuleException(String message){ 30 | super(message); 31 | } 32 | 33 | public PnxModuleException(String message, Throwable cause) { 34 | super(message, cause); 35 | } 36 | 37 | public PnxModuleException(Throwable cause) { 38 | super(cause); 39 | } 40 | 41 | 42 | } 43 | -------------------------------------------------------------------------------- /pnx-test-starter-core/src/main/java/com/pnxtest/core/exceptions/SkipException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.core.exceptions; 23 | 24 | public class SkipException extends RuntimeException{ 25 | 26 | private static final long serialVersionUID = -5619155390244757271L; 27 | 28 | public SkipException(String message){ 29 | super(message); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /pnx-test-starter-core/src/main/java/com/pnxtest/core/exceptions/StepException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.core.exceptions; 23 | 24 | public class StepException extends RuntimeException{ 25 | 26 | 27 | private static final long serialVersionUID = -4140552191549749862L; 28 | 29 | public StepException(String message){ 30 | super(message); 31 | } 32 | 33 | public StepException(String message, Throwable cause) { 34 | super(message, cause); 35 | } 36 | 37 | public StepException(Throwable cause) { 38 | super(cause); 39 | } 40 | 41 | 42 | } 43 | -------------------------------------------------------------------------------- /pnx-test-starter-core/src/main/java/com/pnxtest/core/executors/ClassResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.core.executors; 23 | 24 | import com.pnxtest.core.api.Status; 25 | 26 | import java.util.ArrayList; 27 | import java.util.List; 28 | 29 | /** 30 | * Result DTO of class level 31 | * @author nicolas.chen 32 | */ 33 | public class ClassResult extends AbstractBaseResult { 34 | 35 | private final List results = new ArrayList<>(); 36 | private final TestClass testClass; 37 | 38 | 39 | public ClassResult(TestClass testClass) { 40 | super(); 41 | this.testClass = testClass; 42 | } 43 | 44 | public List getResults() { 45 | return results; 46 | } 47 | 48 | public TestClass getTestClass() { 49 | return testClass; 50 | } 51 | 52 | public void addResult(MethodResult methodResult) { 53 | this.results.add(methodResult); 54 | this.incrementTotal(); 55 | this.incrementDuration(methodResult.getDuration()); 56 | if(methodResult.getStatus() == Status.PASSED){ 57 | this.incrementPassed(); 58 | } 59 | 60 | if(methodResult.getStatus() == Status.FAILED){ 61 | this.incrementFailed(); 62 | } 63 | 64 | if(methodResult.getStatus() == Status.SKIPPED){ 65 | this.incrementSkipped(); 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /pnx-test-starter-core/src/main/java/com/pnxtest/core/executors/DataProviderLog.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.core.executors; 23 | 24 | 25 | import com.pnxtest.core.api.Status; 26 | 27 | public class DataProviderLog { 28 | private int index; 29 | private long startTime; 30 | private long duration; 31 | private Status status; 32 | private String args; 33 | private String remark; 34 | 35 | DataProviderLog(){ 36 | this.startTime = System.nanoTime(); 37 | } 38 | 39 | public int getIndex() { 40 | return index; 41 | } 42 | 43 | public void setIndex(int index) { 44 | this.index = index; 45 | } 46 | 47 | public long getStartTime() { 48 | return startTime; 49 | } 50 | 51 | public void setStartTime(long startTime) { 52 | this.startTime = startTime; 53 | } 54 | 55 | public long getDuration() { 56 | return duration; 57 | } 58 | 59 | public void setDuration(long duration) { 60 | this.duration = duration; 61 | } 62 | 63 | public Status getStatus() { 64 | return status; 65 | } 66 | 67 | public void setStatus(Status status) { 68 | this.status = status; 69 | } 70 | 71 | public String getArgs() { 72 | return args; 73 | } 74 | 75 | public void setArgs(String args) { 76 | this.args = args; 77 | } 78 | 79 | public String getRemark() { 80 | return remark; 81 | } 82 | 83 | public void setRemark(String remark) { 84 | this.remark = remark; 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /pnx-test-starter-core/src/main/java/com/pnxtest/core/executors/IExecutor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.core.executors; 23 | 24 | import java.util.concurrent.ExecutionException; 25 | 26 | public interface IExecutor { 27 | void execute() throws InterruptedException, ExecutionException; 28 | } 29 | -------------------------------------------------------------------------------- /pnx-test-starter-core/src/main/java/com/pnxtest/core/executors/ResultCollector.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.core.executors; 23 | 24 | import java.util.Collections; 25 | import java.util.LinkedHashMap; 26 | import java.util.Map; 27 | 28 | public class ResultCollector extends AbstractBaseResult { 29 | private Map runsResult = Collections.synchronizedMap(new LinkedHashMap<>()); 30 | private final TestSuite testSuite; 31 | 32 | public ResultCollector(TestSuite testSuite){ 33 | super(); 34 | this.testSuite = testSuite; 35 | } 36 | 37 | public Map getRunsResult() { 38 | return runsResult; 39 | } 40 | 41 | public void addRunResult(RunResult runResult) { 42 | this.runsResult.put(runResult.getTestRun(), runResult ); 43 | 44 | this.duration.getAndAdd(runResult.getDuration()); 45 | this.totalCount.getAndAdd(runResult.getTotalCount()); 46 | this.passedCount.getAndAdd(runResult.getPassedCount()); 47 | this.failedCount.getAndAdd(runResult.getFailedCount()); 48 | this.skippedCount.getAndAdd(runResult.getSkippedCount()); 49 | } 50 | 51 | public TestSuite getTestSuite() { 52 | return testSuite; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /pnx-test-starter-core/src/main/java/com/pnxtest/core/executors/RunResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.core.executors; 23 | 24 | import java.util.Collections; 25 | import java.util.LinkedHashMap; 26 | import java.util.Map; 27 | 28 | public class RunResult extends AbstractBaseResult { 29 | private final Map results = Collections.synchronizedMap(new LinkedHashMap<>()); 30 | private final TestRun testRun; 31 | 32 | 33 | public RunResult(TestRun testRun) { 34 | super(); 35 | this.testRun = testRun; 36 | } 37 | 38 | public Map getResults() { 39 | return results; 40 | } 41 | 42 | public void addResult(TestClass testClass, ClassResult classResult){ 43 | this.results.put(testClass, classResult); 44 | this.duration.getAndAdd(classResult.getDuration()); 45 | this.totalCount.getAndAdd(classResult.getTotalCount()); 46 | this.passedCount.getAndAdd(classResult.getPassedCount()); 47 | this.failedCount.getAndAdd(classResult.getFailedCount()); 48 | this.skippedCount.getAndAdd(classResult.getSkippedCount()); 49 | } 50 | 51 | public TestRun getTestRun() { 52 | return testRun; 53 | } 54 | 55 | @Override 56 | public String toString() { 57 | return "RunResult{" + 58 | ", result='" + totalCount + '\'' + 59 | ", duration=" + duration + 60 | '}'; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /pnx-test-starter-core/src/main/java/com/pnxtest/core/executors/Task.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.core.executors; 23 | 24 | import java.util.concurrent.Callable; 25 | 26 | /** 27 | * task in parallel 28 | * @author nicolas.chen 29 | */ 30 | public interface Task extends Callable{ 31 | T run(); 32 | } 33 | -------------------------------------------------------------------------------- /pnx-test-starter-core/src/main/java/com/pnxtest/core/executors/TestCaseTask.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.core.executors; 23 | 24 | public class TestCaseTask implements Task { 25 | private final TestCase testCase; 26 | 27 | TestCaseTask(TestCase testCase){ 28 | this.testCase = testCase; 29 | } 30 | 31 | 32 | @Override 33 | public MethodResult run() { 34 | return testCase.run(); 35 | } 36 | 37 | @Override 38 | public MethodResult call() throws Exception { 39 | return null; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /pnx-test-starter-core/src/main/java/com/pnxtest/core/executors/TestMethodExecutor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.core.executors; 23 | 24 | import java.util.Collection; 25 | import java.util.List; 26 | import java.util.concurrent.ExecutionException; 27 | import java.util.concurrent.ExecutorService; 28 | import java.util.concurrent.Executors; 29 | import java.util.concurrent.Future; 30 | 31 | public class TestMethodExecutor implements IExecutor{ 32 | private final Collection testMethods; 33 | 34 | public TestMethodExecutor(List testMethods) { 35 | this.testMethods = testMethods; 36 | } 37 | 38 | 39 | //Report the results only when all have completed. 40 | @Override 41 | public void execute() throws InterruptedException, ExecutionException { 42 | int numThreads = Math.min(testMethods.size(), 100); 43 | ExecutorService executor = Executors.newFixedThreadPool(numThreads); 44 | List> results = executor.invokeAll(testMethods); 45 | for(Future result : results){ 46 | MethodResult methodResult = result.get(); 47 | //System.out.println("Result:" + methodResult.getResult()); 48 | } 49 | 50 | executor.shutdown(); //always reclaim resources 51 | } 52 | 53 | 54 | } 55 | -------------------------------------------------------------------------------- /pnx-test-starter-core/src/main/java/com/pnxtest/core/executors/TestRunTask.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.core.executors; 23 | 24 | import com.pnxtest.core.outputting.ConsoleLog; 25 | 26 | public class TestRunTask implements Task { 27 | private final TestRun testRun; 28 | 29 | public TestRunTask(TestRun testRun){ 30 | this.testRun = testRun; 31 | } 32 | 33 | @Override 34 | public RunResult run() { 35 | RunResult runResult = new RunResult(testRun); 36 | ConsoleLog.printTestRunOnStart(runResult); 37 | for(TestClass testClass: testRun.getTestClasses()){ 38 | ClassResult classResult = new TestClassTask(testClass).run(); 39 | runResult.addResult(testClass, classResult); 40 | } 41 | 42 | ConsoleLog.printTestRunOnFinish(runResult); 43 | return runResult; 44 | } 45 | 46 | @Override 47 | public RunResult call() throws Exception { 48 | return run(); 49 | } 50 | 51 | public TestRun getTestRun() { 52 | return testRun; 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /pnx-test-starter-core/src/main/java/com/pnxtest/core/helper/PnxHelper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.core.helper; 23 | 24 | import com.pnxtest.core.exceptions.PnxException; 25 | import com.pnxtest.core.steps.Step; 26 | 27 | import java.util.concurrent.TimeUnit; 28 | 29 | /** 30 | * general helpers 31 | * author: nicolas.chen 32 | */ 33 | public class PnxHelper { 34 | private PnxHelper(){} 35 | 36 | public static void await(long timeOut){ 37 | await(timeOut, TimeUnit.MILLISECONDS); 38 | } 39 | 40 | @Step("程序等待{0} {1}") 41 | public static void await(long timeOut, TimeUnit timeUnit){ 42 | try { 43 | if (timeUnit == TimeUnit.DAYS) { 44 | TimeUnit.DAYS.sleep(timeOut); 45 | } 46 | 47 | if (timeUnit == TimeUnit.HOURS) { 48 | TimeUnit.HOURS.sleep(timeOut); 49 | } 50 | 51 | if(timeUnit == TimeUnit.MINUTES){ 52 | TimeUnit.MINUTES.sleep(timeOut); 53 | } 54 | if(timeUnit == TimeUnit.SECONDS){ 55 | TimeUnit.SECONDS.sleep(timeOut); 56 | } 57 | 58 | if(timeUnit == TimeUnit.MILLISECONDS){ 59 | TimeUnit.MILLISECONDS.sleep(timeOut); 60 | } 61 | 62 | if(timeUnit == TimeUnit.MICROSECONDS){ 63 | TimeUnit.MICROSECONDS.sleep(timeOut); 64 | } 65 | 66 | }catch (InterruptedException e){ 67 | throw new PnxException(String.format("%d %s await timeout", timeOut, timeUnit.name()), e); 68 | } 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /pnx-test-starter-core/src/main/java/com/pnxtest/core/outputting/StatsInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.core.outputting; 23 | 24 | import java.io.Serializable; 25 | 26 | public class StatsInfo implements Serializable { 27 | private static final long serialVersionUID = 8639556483861835518L; 28 | 29 | private int totalCount; 30 | private int passedCount; 31 | private int failedCount; 32 | private int skippedCount; 33 | 34 | public StatsInfo() { 35 | } 36 | 37 | public int getTotalCount() { 38 | return totalCount; 39 | } 40 | 41 | public void setTotalCount(int totalCount) { 42 | this.totalCount = totalCount; 43 | } 44 | 45 | public int getPassedCount() { 46 | return passedCount; 47 | } 48 | 49 | public void setPassedCount(int passedCount) { 50 | this.passedCount = passedCount; 51 | } 52 | 53 | public int getFailedCount() { 54 | return failedCount; 55 | } 56 | 57 | public void setFailedCount(int failedCount) { 58 | this.failedCount = failedCount; 59 | } 60 | 61 | public int getSkippedCount() { 62 | return skippedCount; 63 | } 64 | 65 | public void setSkippedCount(int skippedCount) { 66 | this.skippedCount = skippedCount; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /pnx-test-starter-core/src/main/java/com/pnxtest/core/outputting/TestCaseInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.core.outputting; 23 | 24 | import java.io.Serializable; 25 | 26 | public class TestCaseInfo implements Serializable { 27 | private static final long serialVersionUID = 357886840938102531L; 28 | } 29 | -------------------------------------------------------------------------------- /pnx-test-starter-core/src/main/java/com/pnxtest/core/outputting/TestRunInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.core.outputting; 23 | 24 | import com.pnxtest.core.executors.MethodResult; 25 | import com.pnxtest.core.executors.RunResult; 26 | 27 | import java.io.Serializable; 28 | import java.util.LinkedList; 29 | import java.util.List; 30 | 31 | public class TestRunInfo implements Serializable { 32 | private static final long serialVersionUID = -559041460211896831L; 33 | 34 | private final String title; 35 | private List testCases = new LinkedList<>(); 36 | private StatsInfo stats = new StatsInfo(); 37 | 38 | 39 | public TestRunInfo(String title, RunResult runResult) { 40 | this.title = title; 41 | this.stats.setTotalCount(runResult.getTotalCount()); 42 | this.stats.setPassedCount(runResult.getPassedCount()); 43 | this.stats.setFailedCount(runResult.getFailedCount()); 44 | this.stats.setSkippedCount(runResult.getSkippedCount()); 45 | } 46 | 47 | public String getTitle() { 48 | return title; 49 | } 50 | 51 | public List getTestCases() { 52 | return testCases; 53 | } 54 | 55 | public void addTestCase(MethodResult methodResult) { 56 | testCases.add(methodResult); 57 | } 58 | 59 | public void setTestCases(List testCases) { 60 | this.testCases = testCases; 61 | } 62 | 63 | public StatsInfo getStats() { 64 | return stats; 65 | } 66 | 67 | public void setStats(StatsInfo stats) { 68 | this.stats = stats; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /pnx-test-starter-core/src/main/java/com/pnxtest/core/outputting/TestSuiteInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.core.outputting; 23 | 24 | import java.util.ArrayList; 25 | import java.util.List; 26 | 27 | public class TestSuiteInfo { 28 | private List runs = new ArrayList<>(); 29 | private StatsInfo stats = new StatsInfo(); 30 | 31 | public List getRuns() { 32 | return runs; 33 | } 34 | 35 | public void setRuns(List runs) { 36 | this.runs = runs; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /pnx-test-starter-core/src/main/java/com/pnxtest/core/steps/Step.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.core.steps; 23 | 24 | import java.lang.annotation.*; 25 | 26 | @Target(ElementType.METHOD) 27 | @Retention(RetentionPolicy.RUNTIME) 28 | @Documented 29 | public @interface Step { 30 | String value(); 31 | int timeThreshold() default 0; //seconds 32 | } 33 | -------------------------------------------------------------------------------- /pnx-test-starter-core/src/main/java/com/pnxtest/core/steps/StepMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.core.steps; 23 | 24 | public class StepMessage { 25 | private final String content; 26 | private final Type type; 27 | 28 | private StepMessage(String content, Type type) { 29 | this.content = content; 30 | this.type = type; 31 | } 32 | 33 | public String getContent() { 34 | return content; 35 | } 36 | 37 | public Type getType() { 38 | return type; 39 | } 40 | 41 | public enum Type{SUCCESS, INFO, WARNING, ERROR}; 42 | 43 | 44 | public static StepMessage success(String content){ 45 | return new StepMessage(content, Type.SUCCESS); 46 | } 47 | 48 | public static StepMessage warning(String content){ 49 | return new StepMessage(content, Type.WARNING); 50 | } 51 | 52 | public static StepMessage error(String content){ 53 | return new StepMessage(content, Type.ERROR); 54 | } 55 | public static StepMessage info(String content){ 56 | return new StepMessage(content, Type.INFO); 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /pnx-test-starter-core/src/main/java/com/pnxtest/core/steps/Steps.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.core.steps; 23 | 24 | import java.lang.annotation.*; 25 | 26 | @Target({ElementType.FIELD}) 27 | @Retention(RetentionPolicy.RUNTIME) 28 | @Documented 29 | public @interface Steps { 30 | boolean shared() default false; 31 | } 32 | -------------------------------------------------------------------------------- /pnx-test-starter-core/src/main/java/com/pnxtest/core/steps/StepsModule.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.core.steps; 23 | 24 | import com.pnxtest.core.api.Repository; 25 | import com.google.inject.AbstractModule; 26 | import com.google.inject.matcher.Matchers; 27 | 28 | class StepsModule extends AbstractModule { 29 | @Override 30 | protected void configure(){ 31 | bindInterceptor(Matchers.annotatedWith(Repository.class), Matchers.any(), new StepInterceptor()); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /pnx-test-starter-core/src/main/java/com/pnxtest/core/util/FileUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.core.util; 23 | 24 | import java.io.File; 25 | 26 | public class FileUtil { 27 | private FileUtil(){} 28 | 29 | public static boolean checkAndCreateDir(String dir) { 30 | File tdir = new File(dir); 31 | boolean dirExists = tdir.exists(); 32 | if (!dirExists) { 33 | dirExists = tdir.mkdirs(); 34 | } 35 | return dirExists; 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /pnx-test-starter-core/src/main/java/com/pnxtest/core/util/MethodUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.core.util; 23 | 24 | import java.lang.reflect.InvocationTargetException; 25 | import java.lang.reflect.Method; 26 | 27 | public class MethodUtil { 28 | private MethodUtil(){} 29 | 30 | public static Object invokeJvmMethod(final Object obj, final Object[] args, final Method method) throws Throwable{ 31 | try { 32 | method.setAccessible(true); 33 | return method.invoke(obj, args); 34 | } catch(InvocationTargetException | IllegalAccessException ie) { 35 | throw ie.getCause(); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /pnx-test-starter-core/src/test/java/cn/pnxtestframework/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pengtech/pnxtest/ac2dd0fe1cb12a32845a5348cb50e146952f0f11/pnx-test-starter-core/src/test/java/cn/pnxtestframework/.DS_Store -------------------------------------------------------------------------------- /pnx-test-starter-db/.gitignore: -------------------------------------------------------------------------------- 1 | #Intellij project files 2 | .idea 3 | *.iml 4 | target 5 | 6 | -------------------------------------------------------------------------------- /pnx-test-starter-db/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | pnx-test-starter-parent 8 | com.pnxtest 9 | 1.0.2 10 | ../pnx-test-starter-parent 11 | 12 | 13 | 14 | pnx-test-starter-db 15 | pnx-test-starter-db 16 | 17 | 18 | 19 | com.pnxtest 20 | pnx-test-starter-core 21 | 22 | 23 | org.antlr 24 | antlr4-runtime 25 | 26 | 27 | com.zaxxer 28 | HikariCP 29 | 30 | 31 | 32 | 33 | 34 | org.antlr 35 | antlr4-maven-plugin 36 | 37 | 38 | 39 | antlr4 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /pnx-test-starter-db/src/main/antlr4/lexer/ColonStatementLexer.g4: -------------------------------------------------------------------------------- 1 | lexer grammar ColonStatementLexer; 2 | 3 | fragment QUOTE: '\''; 4 | fragment ESCAPE: '\\'; 5 | fragment ESCAPE_QUOTE: ESCAPE QUOTE; 6 | fragment DOUBLE_QUOTE: '"'; 7 | fragment COLON: {_input.LA(2) != ':'}? ':'; 8 | fragment DOUBLE_COLON: {_input.LA(2) == ':'}? '::'; 9 | fragment QUESTION: {_input.LA(2) != '?'}? '?'; 10 | fragment DOUBLE_QUESTION: {_input.LA(2) == '?'}? '??'; 11 | fragment NAME: JAVA_LETTER | [0-9] | '.' | '?.'; 12 | 13 | /* Lovingly lifted from https://github.com/antlr/grammars-v4/blob/master/java/JavaLexer.g4 */ 14 | fragment JAVA_LETTER : [a-zA-Z$_] | ~[\u0000-\u007F\uD800-\uDBFF] | [\uD800-\uDBFF] [\uDC00-\uDFFF]; 15 | 16 | COMMENT: '/*' .*? '*/' | '--' ~('\r' | '\n')* | '//' ~('\r' | '\n')*; 17 | QUOTED_TEXT: QUOTE (ESCAPE_QUOTE | ~'\'')* QUOTE; 18 | DOUBLE_QUOTED_TEXT: DOUBLE_QUOTE (~'"')+ DOUBLE_QUOTE; 19 | ESCAPED_TEXT : ESCAPE . ; 20 | 21 | NAMED_PARAM: COLON (NAME)+; 22 | POSITIONAL_PARAM: QUESTION; 23 | 24 | LITERAL: DOUBLE_COLON | DOUBLE_QUESTION | .; -------------------------------------------------------------------------------- /pnx-test-starter-db/src/main/antlr4/lexer/DefineStatementLexer.g4: -------------------------------------------------------------------------------- 1 | lexer grammar DefineStatementLexer; 2 | 3 | fragment QUOTE: '\'' ; 4 | fragment ESCAPE: '\\' ; 5 | fragment ESCAPE_QUOTE: ESCAPE QUOTE ; 6 | fragment DOUBLE_QUOTE: '"' ; 7 | fragment LT: '<' ; 8 | fragment GT: '>' ; 9 | fragment NAME: JAVA_LETTER | [0-9]; 10 | 11 | /* Lovingly lifted from https://github.com/antlr/grammars-v4/blob/master/java/JavaLexer.g4 */ 12 | fragment JAVA_LETTER : [a-zA-Z$_] | ~[\u0000-\u007F\uD800-\uDBFF] | [\uD800-\uDBFF] [\uDC00-\uDFFF]; 13 | 14 | COMMENT: '/*' .*? '*/' | '--' ~('\r' | '\n')* | '//' ~('\r' | '\n')*; 15 | QUOTED_TEXT: QUOTE (ESCAPE_QUOTE | ~'\'')* QUOTE; 16 | DOUBLE_QUOTED_TEXT: DOUBLE_QUOTE (~'"')+ DOUBLE_QUOTE; 17 | ESCAPED_TEXT : ESCAPE . ; 18 | 19 | DEFINE: LT (NAME)+ GT; 20 | 21 | LITERAL: .; -------------------------------------------------------------------------------- /pnx-test-starter-db/src/main/java/com/pnxtest/db/PnxSql.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2021-2022 3 | This file is part of PnxTest framework. 4 | 5 | PnxTest is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU Affero Public License version 3 as 7 | published by the Free Software Foundation 8 | 9 | PnxTest is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU Affero Public License for more details. 13 | 14 | You should have received a copy of the GNU Affero Public License 15 | along with PnxTest. If not, see . 16 | 17 | For more information, please contact the author at this address: 18 | chen.baker@gmail.com 19 | */ 20 | package com.pnxtest.db; 21 | 22 | import com.pnxtest.db.api.BatchQuery; 23 | import com.pnxtest.db.api.SelectQuery; 24 | import com.pnxtest.db.api.UpdateQuery; 25 | import com.pnxtest.db.internal.*; 26 | 27 | public class PnxSql { 28 | 29 | private PnxSql(){} 30 | 31 | public static SelectQuery select(String sql){ 32 | return new SelectQueryImpl(sql); 33 | } 34 | 35 | public static SelectQuery select(String sql, DbConfig dbConfig){ 36 | return new SelectQueryImpl(sql, dbConfig); 37 | } 38 | 39 | 40 | public static UpdateQuery update(String sql){ 41 | return new UpdateQueryImpl(sql); 42 | } 43 | 44 | public static UpdateQuery update(String sql, DbConfig dbConfig){ 45 | return new UpdateQueryImpl(sql, dbConfig); 46 | } 47 | 48 | public static UpdateQuery insert(String sql){ 49 | return new InsertQueryImpl(sql); 50 | } 51 | 52 | public static UpdateQuery insert(String sql, DbConfig dbConfig){ 53 | return new InsertQueryImpl(sql, dbConfig); 54 | } 55 | 56 | public static UpdateQuery delete(String sql){ 57 | return new DeleteQueryImpl(sql); 58 | } 59 | 60 | public static UpdateQuery delete(String sql, DbConfig dbConfig){ 61 | return new DeleteQueryImpl(sql, dbConfig); 62 | } 63 | 64 | public static BatchQuery batch(String sql){ 65 | return new BatchQueryImpl(sql); 66 | } 67 | 68 | public static BatchQuery batch(String sql, DbConfig dbConfig){ 69 | return new BatchQueryImpl(sql, dbConfig); 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /pnx-test-starter-db/src/main/java/com/pnxtest/db/api/BatchQuery.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2021-2022 3 | This file is part of PnxTest framework. 4 | 5 | PnxTest is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU Affero Public License version 3 as 7 | published by the Free Software Foundation 8 | 9 | PnxTest is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU Affero Public License for more details. 13 | 14 | You should have received a copy of the GNU Affero Public License 15 | along with PnxTest. If not, see . 16 | 17 | For more information, please contact the author at this address: 18 | chen.baker@gmail.com 19 | */ 20 | package com.pnxtest.db.api; 21 | 22 | import java.util.Iterator; 23 | import java.util.List; 24 | import java.util.Map; 25 | 26 | //batch insert or update 27 | public interface BatchQuery { 28 | BatchQuery values(Iterator> values); 29 | BatchQuery values(Iterable> values); 30 | 31 | BatchQuery namedValues(Iterator> values); 32 | BatchQuery namedValues(Iterable> values); 33 | 34 | int[] execute(); 35 | 36 | } 37 | -------------------------------------------------------------------------------- /pnx-test-starter-db/src/main/java/com/pnxtest/db/api/Column.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2021-2022 3 | This file is part of PnxTest framework. 4 | 5 | PnxTest is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU Affero Public License version 3 as 7 | published by the Free Software Foundation 8 | 9 | PnxTest is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU Affero Public License for more details. 13 | 14 | You should have received a copy of the GNU Affero Public License 15 | along with PnxTest. If not, see . 16 | 17 | For more information, please contact the author at this address: 18 | chen.baker@gmail.com 19 | */ 20 | package com.pnxtest.db.api; 21 | 22 | import java.lang.annotation.ElementType; 23 | import java.lang.annotation.Retention; 24 | import java.lang.annotation.RetentionPolicy; 25 | import java.lang.annotation.Target; 26 | 27 | @Target(ElementType.FIELD) 28 | @Retention(RetentionPolicy.RUNTIME) 29 | public @interface Column { 30 | String name(); 31 | } 32 | -------------------------------------------------------------------------------- /pnx-test-starter-db/src/main/java/com/pnxtest/db/api/Entity.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2021-2022 3 | This file is part of PnxTest framework. 4 | 5 | PnxTest is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU Affero Public License version 3 as 7 | published by the Free Software Foundation 8 | 9 | PnxTest is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU Affero Public License for more details. 13 | 14 | You should have received a copy of the GNU Affero Public License 15 | along with PnxTest. If not, see . 16 | 17 | For more information, please contact the author at this address: 18 | chen.baker@gmail.com 19 | */ 20 | package com.pnxtest.db.api; 21 | 22 | import java.lang.annotation.ElementType; 23 | import java.lang.annotation.Retention; 24 | import java.lang.annotation.RetentionPolicy; 25 | import java.lang.annotation.Target; 26 | 27 | @Target(ElementType.TYPE) 28 | @Retention(RetentionPolicy.RUNTIME) 29 | public @interface Entity { 30 | } 31 | -------------------------------------------------------------------------------- /pnx-test-starter-db/src/main/java/com/pnxtest/db/api/Query.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2021-2022 3 | This file is part of PnxTest framework. 4 | 5 | PnxTest is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU Affero Public License version 3 as 7 | published by the Free Software Foundation 8 | 9 | PnxTest is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU Affero Public License for more details. 13 | 14 | You should have received a copy of the GNU Affero Public License 15 | along with PnxTest. If not, see . 16 | 17 | For more information, please contact the author at this address: 18 | chen.baker@gmail.com 19 | */ 20 | package com.pnxtest.db.api; 21 | 22 | public interface Query { 23 | T bind(String name, Object value); 24 | T bind(int positionIndex, Object value); 25 | 26 | } 27 | -------------------------------------------------------------------------------- /pnx-test-starter-db/src/main/java/com/pnxtest/db/api/SelectQuery.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2021-2022 3 | This file is part of PnxTest framework. 4 | 5 | PnxTest is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU Affero Public License version 3 as 7 | published by the Free Software Foundation 8 | 9 | PnxTest is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU Affero Public License for more details. 13 | 14 | You should have received a copy of the GNU Affero Public License 15 | along with PnxTest. If not, see . 16 | 17 | For more information, please contact the author at this address: 18 | chen.baker@gmail.com 19 | */ 20 | package com.pnxtest.db.api; 21 | 22 | import java.util.List; 23 | import java.util.Map; 24 | import java.util.Optional; 25 | 26 | public interface SelectQuery extends Query{ 27 | Optional> asOne(); 28 | List> asList(); 29 | 30 | Optional asOne(Class mapToClass); 31 | List asList(Class mapToClass); 32 | 33 | } 34 | -------------------------------------------------------------------------------- /pnx-test-starter-db/src/main/java/com/pnxtest/db/api/UpdateQuery.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2021-2022 3 | This file is part of PnxTest framework. 4 | 5 | PnxTest is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU Affero Public License version 3 as 7 | published by the Free Software Foundation 8 | 9 | PnxTest is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU Affero Public License for more details. 13 | 14 | You should have received a copy of the GNU Affero Public License 15 | along with PnxTest. If not, see . 16 | 17 | For more information, please contact the author at this address: 18 | chen.baker@gmail.com 19 | */ 20 | package com.pnxtest.db.api; 21 | 22 | public interface UpdateQuery extends Query { 23 | int execute(); 24 | } 25 | -------------------------------------------------------------------------------- /pnx-test-starter-db/src/main/java/com/pnxtest/db/internal/InsertQueryImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2021-2022 3 | This file is part of PnxTest framework. 4 | 5 | PnxTest is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU Affero Public License version 3 as 7 | published by the Free Software Foundation 8 | 9 | PnxTest is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU Affero Public License for more details. 13 | 14 | You should have received a copy of the GNU Affero Public License 15 | along with PnxTest. If not, see . 16 | 17 | For more information, please contact the author at this address: 18 | chen.baker@gmail.com 19 | */ 20 | package com.pnxtest.db.internal; 21 | 22 | import com.pnxtest.core.steps.PnxSteps; 23 | import com.pnxtest.db.DbConfig; 24 | import com.pnxtest.db.api.UpdateQuery; 25 | 26 | import javax.sql.DataSource; 27 | import java.sql.Connection; 28 | import java.sql.PreparedStatement; 29 | import java.sql.SQLException; 30 | 31 | public class InsertQueryImpl extends BaseQuery implements UpdateQuery{ 32 | public InsertQueryImpl(String sql){ 33 | super(sql); 34 | } 35 | 36 | public InsertQueryImpl(String sql, DbConfig dbConfig){ 37 | super(sql, dbConfig); 38 | } 39 | 40 | 41 | @Override 42 | public int execute() { 43 | DataSource ds = getCurrentDataSource(); 44 | ParsedSql parsedSql = parseBinder(); 45 | //insert 46 | PnxSteps.start(parsedSql.getSql(), "SQL", "Insert"); 47 | String subKey = parsedSql.getSql().substring(0, 6).toLowerCase(); 48 | if(!subKey.equalsIgnoreCase("insert")){ 49 | PnxSteps.success(getDescription() + "\nno any records affected due to wrong sql query"); 50 | PnxSteps.end(); 51 | return 0; 52 | } 53 | 54 | try(Connection conn = ds.getConnection(); 55 | PreparedStatement pst = conn.prepareStatement(parsedSql.getSql())){ 56 | setPstBinding(parsedSql, pst); 57 | int updatedCount = pst.executeUpdate(); 58 | PnxSteps.success(getDescription() + "\n" + updatedCount + " records inserted"); 59 | PnxSteps.end(); 60 | return updatedCount; 61 | }catch (SQLException ex){ 62 | throw new PnxSqlException(ex); 63 | } 64 | } 65 | 66 | 67 | } 68 | -------------------------------------------------------------------------------- /pnx-test-starter-db/src/main/java/com/pnxtest/db/internal/ParsedParameters.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2021-2022 3 | This file is part of PnxTest framework. 4 | 5 | PnxTest is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU Affero Public License version 3 as 7 | published by the Free Software Foundation 8 | 9 | PnxTest is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU Affero Public License for more details. 13 | 14 | You should have received a copy of the GNU Affero Public License 15 | along with PnxTest. If not, see . 16 | 17 | For more information, please contact the author at this address: 18 | chen.baker@gmail.com 19 | */ 20 | package com.pnxtest.db.internal; 21 | 22 | import java.util.ArrayList; 23 | import java.util.Collections; 24 | import java.util.List; 25 | 26 | class ParsedParameters { 27 | private final boolean positional; 28 | private final List parameterNames; 29 | 30 | ParsedParameters(boolean positional, List parameterNames) { 31 | this.positional = positional; 32 | this.parameterNames = Collections.unmodifiableList(new ArrayList<>(parameterNames)); 33 | } 34 | 35 | 36 | public boolean isPositional() { 37 | return positional; 38 | } 39 | 40 | 41 | public int getParameterCount() { 42 | return parameterNames.size(); 43 | } 44 | 45 | 46 | public List getParameterNames() { 47 | return parameterNames; 48 | } 49 | 50 | 51 | 52 | public static ParsedParameters named(List names) { 53 | if (names.contains(ParsedSql.POSITIONAL_PARAM)) { 54 | throw new IllegalArgumentException("Named parameters " 55 | + "list must not contain positional parameter " 56 | + "\"" + ParsedSql.POSITIONAL_PARAM + "\""); 57 | } 58 | return new ParsedParameters(false, names); 59 | } 60 | 61 | 62 | public static ParsedParameters positional(int count) { 63 | return new ParsedParameters(true, Collections.nCopies(count, "?")); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /pnx-test-starter-db/src/main/java/com/pnxtest/db/internal/PnxSqlException.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2021-2022 3 | This file is part of PnxTest framework. 4 | 5 | PnxTest is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU Affero Public License version 3 as 7 | published by the Free Software Foundation 8 | 9 | PnxTest is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU Affero Public License for more details. 13 | 14 | You should have received a copy of the GNU Affero Public License 15 | along with PnxTest. If not, see . 16 | 17 | For more information, please contact the author at this address: 18 | chen.baker@gmail.com 19 | */ 20 | package com.pnxtest.db.internal; 21 | 22 | import com.pnxtest.core.exceptions.PnxModuleException; 23 | 24 | class PnxSqlException extends PnxModuleException { 25 | 26 | private static final long serialVersionUID = 8748023436177789850L; 27 | public PnxSqlException(String message){ 28 | super(message); 29 | } 30 | 31 | public PnxSqlException(String message, Throwable cause) { 32 | super(message, cause); 33 | } 34 | 35 | public PnxSqlException(Throwable cause) { 36 | super(cause); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /pnx-test-starter-db/src/main/java/com/pnxtest/db/internal/UpdateQueryImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2021-2022 3 | This file is part of PnxTest framework. 4 | 5 | PnxTest is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU Affero Public License version 3 as 7 | published by the Free Software Foundation 8 | 9 | PnxTest is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU Affero Public License for more details. 13 | 14 | You should have received a copy of the GNU Affero Public License 15 | along with PnxTest. If not, see . 16 | 17 | For more information, please contact the author at this address: 18 | chen.baker@gmail.com 19 | */ 20 | package com.pnxtest.db.internal; 21 | 22 | import com.pnxtest.core.steps.PnxSteps; 23 | import com.pnxtest.db.DbConfig; 24 | import com.pnxtest.db.api.UpdateQuery; 25 | 26 | import javax.sql.DataSource; 27 | import java.sql.Connection; 28 | import java.sql.PreparedStatement; 29 | import java.sql.SQLException; 30 | 31 | public class UpdateQueryImpl extends BaseQuery implements UpdateQuery{ 32 | public UpdateQueryImpl(String sql){ 33 | super(sql); 34 | } 35 | 36 | public UpdateQueryImpl(String sql, DbConfig dbConfig){ 37 | super(sql, dbConfig); 38 | } 39 | 40 | 41 | @Override 42 | public int execute() { 43 | DataSource ds = getCurrentDataSource(); 44 | ParsedSql parsedSql = parseBinder(); 45 | //update 46 | PnxSteps.start(parsedSql.getSql(), "SQL", "Update"); 47 | String subKey = parsedSql.getSql().substring(0, 6).toLowerCase(); 48 | if(!subKey.equalsIgnoreCase("update")){ 49 | PnxSteps.success(getDescription() + "\nno any records affected due to wrong sql query"); 50 | PnxSteps.end(); 51 | return 0; 52 | } 53 | 54 | try(Connection conn = ds.getConnection(); 55 | PreparedStatement pst = conn.prepareStatement(parsedSql.getSql())){ 56 | setPstBinding(parsedSql, pst); 57 | int updatedCount = pst.executeUpdate(); 58 | PnxSteps.success(getDescription() + "\n" + updatedCount + " records updated"); 59 | PnxSteps.end(); 60 | return updatedCount; 61 | }catch (SQLException ex){ 62 | throw new PnxSqlException(ex); 63 | } 64 | } 65 | 66 | 67 | } 68 | -------------------------------------------------------------------------------- /pnx-test-starter-http/.gitignore: -------------------------------------------------------------------------------- 1 | #Intellij project files 2 | .idea 3 | *.iml 4 | target 5 | 6 | -------------------------------------------------------------------------------- /pnx-test-starter-http/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | pnx-test-starter-parent 8 | com.pnxtest 9 | 1.0.2 10 | ../pnx-test-starter-parent 11 | 12 | 13 | 14 | pnx-test-starter-http 15 | pnx-test-starter-http 16 | 17 | 18 | 19 | com.pnxtest 20 | pnx-test-starter-core 21 | 22 | 23 | 24 | org.apache.httpcomponents 25 | httpclient 26 | 27 | 28 | org.apache.httpcomponents 29 | httpmime 30 | 31 | 32 | org.apache.httpcomponents 33 | httpcore-nio 34 | 35 | 36 | com.fasterxml.jackson.core 37 | jackson-databind 38 | 39 | 40 | -------------------------------------------------------------------------------- /pnx-test-starter-http/src/main/java/com/pnxtest/http/api/Body.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.http.api; 23 | 24 | 25 | import com.pnxtest.http.internal.BodyPart; 26 | import com.pnxtest.http.internal.MultipartMode; 27 | 28 | import java.nio.charset.Charset; 29 | import java.nio.charset.StandardCharsets; 30 | import java.util.Collection; 31 | import java.util.Collections; 32 | 33 | public interface Body { 34 | boolean isMultiPart(); 35 | 36 | boolean isEntityBody(); 37 | 38 | default Charset getCharset(){ 39 | return StandardCharsets.UTF_8; 40 | } 41 | 42 | default Collection multiParts(){ 43 | return Collections.emptyList(); 44 | } 45 | 46 | default BodyPart bodyPart(){ 47 | return null; 48 | } 49 | 50 | default MultipartMode getMode(){ 51 | return MultipartMode.BROWSER_COMPATIBLE; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /pnx-test-starter-http/src/main/java/com/pnxtest/http/api/Client.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.http.api; 23 | 24 | import java.util.function.Function; 25 | import java.util.stream.Stream; 26 | 27 | public interface Client { 28 | Object getClient(); 29 | HttpResponse request(HttpRequest request, Function> transformer); 30 | Stream close(); 31 | 32 | void registerShutdownHook(); 33 | } 34 | -------------------------------------------------------------------------------- /pnx-test-starter-http/src/main/java/com/pnxtest/http/api/GetRequest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.http.api; 23 | 24 | public interface GetRequest extends HttpRequest { 25 | } 26 | -------------------------------------------------------------------------------- /pnx-test-starter-http/src/main/java/com/pnxtest/http/api/Header.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.http.api; 23 | 24 | public interface Header { 25 | String getName(); 26 | String getValue(); 27 | } 28 | -------------------------------------------------------------------------------- /pnx-test-starter-http/src/main/java/com/pnxtest/http/api/HttpRequestWithBody.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.http.api; 23 | 24 | 25 | import com.pnxtest.http.internal.ContentType; 26 | 27 | import java.io.File; 28 | import java.io.InputStream; 29 | import java.nio.charset.Charset; 30 | import java.util.Collection; 31 | import java.util.Map; 32 | 33 | public interface HttpRequestWithBody extends HttpRequest { 34 | HttpRequestWithBody charset(Charset charset); 35 | 36 | MultipartBody field(String name, Collection value); 37 | 38 | MultipartBody field(String name, File file); 39 | 40 | MultipartBody field(String name, File file, String contentType); 41 | 42 | MultipartBody field(String name, Object value); 43 | 44 | MultipartBody field(String name, Object value, String contentType); 45 | 46 | MultipartBody fields(Map parameters); 47 | 48 | MultipartBody field(String name, InputStream stream, ContentType contentType, String fileName); 49 | 50 | MultipartBody field(String name, InputStream stream, String fileName); 51 | 52 | RequestBodyEntity body(String body); 53 | 54 | RequestBodyEntity body(Object body); 55 | 56 | RequestBodyEntity body(byte[] body); 57 | 58 | Charset getCharset(); 59 | } 60 | -------------------------------------------------------------------------------- /pnx-test-starter-http/src/main/java/com/pnxtest/http/api/HttpResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.http.api; 23 | 24 | 25 | import com.pnxtest.http.internal.HttpParsingException; 26 | import com.pnxtest.http.internal.Headers; 27 | 28 | import java.util.Optional; 29 | import java.util.function.Consumer; 30 | import java.util.function.Function; 31 | 32 | 33 | public interface HttpResponse { 34 | 35 | int getStatus(); 36 | 37 | String getStatusText(); 38 | 39 | Headers getHeaders(); 40 | 41 | T getBody(); 42 | 43 | Optional getParsingError(); 44 | 45 | V mapBody(Function func); 46 | 47 | 48 | HttpResponse map(Function func); 49 | 50 | 51 | HttpResponse ifSuccess(Consumer> consumer); 52 | 53 | HttpResponse ifFailure(Consumer> consumer); 54 | 55 | HttpResponse ifFailure(Class errorClass, Consumer> consumer); 56 | 57 | boolean isSuccess(); 58 | 59 | E mapError(Class errorClass); 60 | } 61 | -------------------------------------------------------------------------------- /pnx-test-starter-http/src/main/java/com/pnxtest/http/api/IHttpConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.http.api; 23 | 24 | import com.pnxtest.core.api.IModConfig; 25 | import com.pnxtest.http.HttpConfig; 26 | 27 | public interface IHttpConfig extends IModConfig { 28 | 29 | HttpConfig accept(); 30 | 31 | } 32 | -------------------------------------------------------------------------------- /pnx-test-starter-http/src/main/java/com/pnxtest/http/api/MultipartBody.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.http.api; 23 | 24 | import com.pnxtest.http.internal.MultipartMode; 25 | import com.pnxtest.http.internal.ContentType; 26 | 27 | import java.io.File; 28 | import java.io.InputStream; 29 | import java.nio.charset.Charset; 30 | import java.util.Collection; 31 | 32 | /** 33 | * Represents a multi-part body builder for a request. 34 | */ 35 | public interface MultipartBody extends HttpRequest, Body { 36 | 37 | MultipartBody field(String name, String value); 38 | 39 | MultipartBody field(String name, String value, String contentType); 40 | 41 | MultipartBody field(String name, Collection values); 42 | 43 | MultipartBody field(String name, File file); 44 | 45 | MultipartBody field(String name, File file, String contentType); 46 | 47 | MultipartBody field(String name, InputStream value, ContentType contentType); 48 | 49 | MultipartBody field(String name, InputStream stream, ContentType contentType, String fileName); 50 | 51 | MultipartBody field(String name, byte[] bytes, ContentType contentType, String fileName); 52 | 53 | MultipartBody field(String name, InputStream stream, String fileName); 54 | 55 | MultipartBody field(String name, byte[] bytes, String fileName); 56 | 57 | MultipartBody charset(Charset charset); 58 | 59 | MultipartBody contentType(String mimeType); 60 | 61 | MultipartBody mode(MultipartMode value); 62 | 63 | } 64 | -------------------------------------------------------------------------------- /pnx-test-starter-http/src/main/java/com/pnxtest/http/api/ObjectMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.http.api; 23 | 24 | 25 | import com.pnxtest.http.internal.GenericType; 26 | 27 | public interface ObjectMapper { 28 | T readValue(String value, Class valueType); 29 | T readValue(String value, GenericType valueType); 30 | String writeValue(Object value); 31 | } 32 | -------------------------------------------------------------------------------- /pnx-test-starter-http/src/main/java/com/pnxtest/http/api/RawResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.http.api; 23 | 24 | import com.pnxtest.http.HttpConfig; 25 | import com.pnxtest.http.internal.Headers; 26 | 27 | import java.io.InputStream; 28 | import java.io.InputStreamReader; 29 | 30 | public interface RawResponse { 31 | int getStatus(); 32 | String getStatusText(); 33 | Headers getHeaders(); 34 | InputStream getContent(); 35 | byte[] getContentAsBytes(); 36 | String getContentAsString(); 37 | String getContentAsString(String charset); 38 | InputStreamReader getContentReader(); 39 | boolean hasContent(); 40 | String getContentType(); 41 | String getEncoding(); 42 | HttpConfig getHttpConfig(); 43 | } 44 | -------------------------------------------------------------------------------- /pnx-test-starter-http/src/main/java/com/pnxtest/http/api/RequestBodyEntity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.http.api; 23 | 24 | import java.nio.charset.Charset; 25 | 26 | public interface RequestBodyEntity extends HttpRequest, Body { 27 | RequestBodyEntity body(byte[] bodyBytes); 28 | 29 | RequestBodyEntity body(String bodyAsString); 30 | 31 | RequestBodyEntity charset(Charset charset); 32 | } 33 | -------------------------------------------------------------------------------- /pnx-test-starter-http/src/main/java/com/pnxtest/http/api/RequestInterceptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.http.api; 23 | 24 | import org.apache.http.HttpRequestInterceptor; 25 | 26 | public interface RequestInterceptor extends HttpRequestInterceptor { 27 | } 28 | -------------------------------------------------------------------------------- /pnx-test-starter-http/src/main/java/com/pnxtest/http/api/ResponseInterceptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.http.api; 23 | 24 | import org.apache.http.HttpResponseInterceptor; 25 | 26 | public interface ResponseInterceptor extends HttpResponseInterceptor { 27 | } 28 | -------------------------------------------------------------------------------- /pnx-test-starter-http/src/main/java/com/pnxtest/http/internal/ApacheDeleteWithBody.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.http.internal; 23 | 24 | import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; 25 | 26 | import java.net.URI; 27 | 28 | class ApacheDeleteWithBody extends HttpEntityEnclosingRequestBase { 29 | private static final String METHOD_NAME = "DELETE"; 30 | 31 | public String getMethod() { 32 | return METHOD_NAME; 33 | } 34 | 35 | ApacheDeleteWithBody(final String uri) { 36 | super(); 37 | setURI(URI.create(uri)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /pnx-test-starter-http/src/main/java/com/pnxtest/http/internal/ApacheNoRedirectStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.http.internal; 23 | 24 | import org.apache.http.HttpRequest; 25 | import org.apache.http.HttpResponse; 26 | import org.apache.http.client.RedirectStrategy; 27 | import org.apache.http.client.methods.HttpUriRequest; 28 | import org.apache.http.protocol.HttpContext; 29 | 30 | class ApacheNoRedirectStrategy implements RedirectStrategy { 31 | @Override 32 | public boolean isRedirected(HttpRequest request, HttpResponse response, HttpContext context) { 33 | return false; 34 | } 35 | 36 | @Override 37 | public HttpUriRequest getRedirect(HttpRequest request, HttpResponse response, HttpContext context) { 38 | return null; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /pnx-test-starter-http/src/main/java/com/pnxtest/http/internal/ApachePatchWithBody.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.http.internal; 23 | 24 | import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; 25 | 26 | import java.net.URI; 27 | 28 | class ApachePatchWithBody extends HttpEntityEnclosingRequestBase { 29 | private static final String METHOD_NAME = "PATCH"; 30 | 31 | public String getMethod() { 32 | return METHOD_NAME; 33 | } 34 | 35 | ApachePatchWithBody(final String uri) { 36 | super(); 37 | setURI(URI.create(uri)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /pnx-test-starter-http/src/main/java/com/pnxtest/http/internal/ApacheRequestWithBody.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.http.internal; 23 | 24 | 25 | import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; 26 | 27 | import java.net.URI; 28 | 29 | class ApacheRequestWithBody extends HttpEntityEnclosingRequestBase { 30 | private HttpMethod method; 31 | 32 | public ApacheRequestWithBody(HttpMethod method, String uri){ 33 | this.method = method; 34 | setURI(URI.create(uri)); 35 | } 36 | @Override 37 | public String getMethod() { 38 | return method.name(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /pnx-test-starter-http/src/main/java/com/pnxtest/http/internal/BaseApacheClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.http.internal; 23 | 24 | import com.pnxtest.http.api.HttpResponse; 25 | import com.pnxtest.http.api.RawResponse; 26 | import org.apache.http.auth.AuthScope; 27 | import org.apache.http.auth.UsernamePasswordCredentials; 28 | import org.apache.http.client.CredentialsProvider; 29 | import org.apache.http.impl.client.BasicCredentialsProvider; 30 | 31 | import java.util.function.Function; 32 | 33 | abstract class BaseApacheClient { 34 | 35 | protected CredentialsProvider toApacheCreds(Proxy proxy) { 36 | if(proxy != null && proxy.isAuthenticated()) { 37 | CredentialsProvider proxyCreds = new BasicCredentialsProvider(); 38 | proxyCreds.setCredentials(new AuthScope(proxy.getHost(), proxy.getPort()), 39 | new UsernamePasswordCredentials(proxy.getUsername(), proxy.getPassword())); 40 | return proxyCreds; 41 | } 42 | return null; 43 | } 44 | 45 | protected HttpResponse transformBody(Function> transformer, RawResponse rr) { 46 | try { 47 | return transformer.apply(rr); 48 | }catch (RuntimeException e){ 49 | String originalBody = recoverBody(rr); 50 | return new BasicResponse(rr, originalBody, e); 51 | } 52 | } 53 | 54 | private String recoverBody(RawResponse rr){ 55 | try { 56 | return rr.getContentAsString(); 57 | }catch (Exception e){ 58 | return null; 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /pnx-test-starter-http/src/main/java/com/pnxtest/http/internal/BasicResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.http.internal; 23 | 24 | import com.pnxtest.http.api.RawResponse; 25 | 26 | class BasicResponse extends BaseResponse { 27 | private final T body; 28 | 29 | public BasicResponse(RawResponse httpResponse, T body) { 30 | super(httpResponse); 31 | this.body = body; 32 | } 33 | 34 | public BasicResponse(RawResponse httpResponse, String ogBody, RuntimeException ex) { 35 | this(httpResponse, null); 36 | setParsingException(ogBody, ex); 37 | } 38 | 39 | @Override 40 | public T getBody() { 41 | return body; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /pnx-test-starter-http/src/main/java/com/pnxtest/http/internal/BodyPart.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.http.internal; 23 | 24 | import java.nio.charset.StandardCharsets; 25 | 26 | public abstract class BodyPart implements Comparable { ; 27 | private final String name; 28 | private final T value; 29 | private final String contentType; 30 | private final Class partType; 31 | 32 | protected BodyPart(T value, String name, String contentType) { 33 | this.name = name; 34 | this.value = value; 35 | this.contentType = contentType; 36 | this.partType = value.getClass(); 37 | } 38 | 39 | public T getValue() { 40 | return value; 41 | } 42 | 43 | public Class getPartType(){ 44 | return partType; 45 | } 46 | 47 | public String getContentType() { 48 | if(contentType == null){ 49 | if(isFile()){ 50 | return ContentType.APPLICATION_OCTET_STREAM.toString(); 51 | } 52 | return ContentType.APPLICATION_FORM_URLENCODED.withCharset(StandardCharsets.UTF_8).toString(); 53 | } 54 | return contentType; 55 | } 56 | 57 | public String getName() { 58 | return name == null ? "" : name; 59 | } 60 | 61 | public String getFileName(){ 62 | return null; 63 | } 64 | 65 | @Override 66 | public int compareTo(Object o) { 67 | if(o instanceof BodyPart){ 68 | return getName().compareTo(((BodyPart)o).getName()); 69 | } 70 | return 0; 71 | } 72 | 73 | 74 | abstract public boolean isFile(); 75 | } 76 | -------------------------------------------------------------------------------- /pnx-test-starter-http/src/main/java/com/pnxtest/http/internal/BodyString.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.http.internal; 23 | 24 | import java.nio.charset.Charset; 25 | 26 | class BodyString extends BodyPart { 27 | BodyString(String bodyAsString, Charset charset) { 28 | super(bodyAsString, null, null); 29 | } 30 | 31 | @Override 32 | public boolean isFile() { 33 | return false; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /pnx-test-starter-http/src/main/java/com/pnxtest/http/internal/ByteArrayBody.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.http.internal; 23 | 24 | class ByteArrayBody extends BodyPart { 25 | ByteArrayBody(byte[] bodyBytes) { 26 | super(bodyBytes, null, null); 27 | } 28 | 29 | @Override 30 | public boolean isFile() { 31 | return false; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /pnx-test-starter-http/src/main/java/com/pnxtest/http/internal/ByteArrayPart.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.http.internal; 23 | 24 | 25 | class ByteArrayPart extends BodyPart { 26 | private final String fileName; 27 | 28 | ByteArrayPart(String name, byte[] bytes, ContentType contentType, String fileName) { 29 | super(bytes, name, contentType.toString()); 30 | this.fileName = fileName; 31 | } 32 | 33 | @Override 34 | public String getFileName() { 35 | return fileName; 36 | } 37 | 38 | @Override 39 | public boolean isFile() { 40 | return true; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /pnx-test-starter-http/src/main/java/com/pnxtest/http/internal/Empty.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.http.internal; 23 | 24 | class Empty { 25 | private Empty(){} 26 | } 27 | -------------------------------------------------------------------------------- /pnx-test-starter-http/src/main/java/com/pnxtest/http/internal/EmptyResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.http.internal; 23 | 24 | import com.pnxtest.http.api.RawResponse; 25 | 26 | class EmptyResponse extends BaseResponse { 27 | EmptyResponse(RawResponse response) { 28 | super(response); 29 | } 30 | 31 | @Override 32 | public Empty getBody() { 33 | return null; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /pnx-test-starter-http/src/main/java/com/pnxtest/http/internal/FilePart.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.http.internal; 23 | 24 | import java.io.File; 25 | 26 | class FilePart extends BodyPart { 27 | private String fileName; 28 | 29 | public FilePart(File file, String name) { 30 | this(file, name, null); 31 | } 32 | 33 | public FilePart(File file, String name, String contentType) { 34 | super(file, name, contentType); 35 | this.fileName = file.getName(); 36 | } 37 | 38 | @Override 39 | public boolean isFile() { 40 | return true; 41 | } 42 | 43 | @Override 44 | public String getFileName(){ 45 | return null; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /pnx-test-starter-http/src/main/java/com/pnxtest/http/internal/FileResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.http.internal; 23 | 24 | import com.pnxtest.core.environment.PnxContext; 25 | import com.pnxtest.http.api.RawResponse; 26 | 27 | import java.io.File; 28 | import java.io.IOException; 29 | import java.nio.file.Path; 30 | import java.nio.file.*; 31 | 32 | class FileResponse extends BaseResponse { 33 | private File body; 34 | 35 | public FileResponse(RawResponse r, String pathOrFilename) { 36 | super(r); 37 | try { 38 | //overwrite existing file, if exists 39 | CopyOption[] options = new CopyOption[]{ 40 | StandardCopyOption.REPLACE_EXISTING 41 | }; 42 | 43 | Path target; 44 | if(!pathOrFilename.contains("/")){ 45 | target = Paths.get(PnxContext.getTestResultLocation(), "download", pathOrFilename); 46 | File location = target.getParent().toFile(); 47 | if(!location.exists()){ 48 | location.mkdirs(); 49 | } 50 | }else{ 51 | target = Paths.get(pathOrFilename); 52 | } 53 | Files.copy(r.getContent(), target, options); 54 | body = target.toFile(); 55 | } catch (IOException e) { 56 | throw new HttpException(String.format("specified file store location<%s> does not exist, please create it firstly!", pathOrFilename), e); 57 | } 58 | } 59 | 60 | @Override 61 | public File getBody() { 62 | return body; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /pnx-test-starter-http/src/main/java/com/pnxtest/http/internal/GenericType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.http.internal; 23 | 24 | import java.lang.reflect.ParameterizedType; 25 | import java.lang.reflect.Type; 26 | 27 | public abstract class GenericType implements Comparable> { 28 | protected final Type type; 29 | 30 | protected GenericType() { 31 | Type superClass = this.getClass().getGenericSuperclass(); 32 | if (superClass instanceof Class) { 33 | throw new IllegalArgumentException("Internal error: TypeReference constructed without actual type information"); 34 | } else { 35 | this.type = ((ParameterizedType)superClass).getActualTypeArguments()[0]; 36 | } 37 | } 38 | 39 | public Type getType() { 40 | return this.type; 41 | } 42 | 43 | public int compareTo(GenericType o) { 44 | return 0; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /pnx-test-starter-http/src/main/java/com/pnxtest/http/internal/HttpConfigException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.http.internal; 23 | 24 | public class HttpConfigException extends HttpException { 25 | public HttpConfigException(Exception e){ 26 | super(e); 27 | } 28 | 29 | public HttpConfigException(String msg) { 30 | super(msg); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /pnx-test-starter-http/src/main/java/com/pnxtest/http/internal/HttpException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.http.internal; 23 | 24 | import java.util.Collection; 25 | import java.util.stream.Collectors; 26 | 27 | public class HttpException extends RuntimeException { 28 | 29 | private static final long serialVersionUID = -3067438387805337395L; 30 | 31 | public HttpException(Exception e) { 32 | super(e); 33 | } 34 | 35 | public HttpException(String msg) { 36 | super(msg); 37 | } 38 | 39 | public HttpException(Throwable ex) { 40 | super(ex); 41 | } 42 | 43 | public HttpException(String message, Throwable e) { 44 | super(message, e); 45 | } 46 | 47 | 48 | public HttpException(Collection ex) { 49 | super(ex.stream().map(e -> e.getClass().getName() + " " + e.getMessage()).collect(Collectors.joining("\n"))); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /pnx-test-starter-http/src/main/java/com/pnxtest/http/internal/HttpGateway.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.http.internal; 23 | 24 | import org.apache.http.protocol.HttpProcessor; 25 | 26 | public abstract class HttpGateway implements HttpProcessor { 27 | 28 | } 29 | -------------------------------------------------------------------------------- /pnx-test-starter-http/src/main/java/com/pnxtest/http/internal/HttpMethod.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.http.internal; 23 | 24 | import java.util.HashMap; 25 | import java.util.HashSet; 26 | import java.util.Map; 27 | import java.util.Set; 28 | 29 | public class HttpMethod { 30 | private static final Map REGISTRY = new HashMap<>(); 31 | 32 | public static final HttpMethod GET = valueOf("GET"); 33 | public static final HttpMethod POST = valueOf("POST"); 34 | public static final HttpMethod PUT = valueOf("PUT"); 35 | public static final HttpMethod DELETE = valueOf("DELETE"); 36 | public static final HttpMethod PATCH = valueOf("PATCH"); 37 | public static final HttpMethod HEAD = valueOf("HEAD"); 38 | public static final HttpMethod OPTIONS = valueOf("OPTIONS"); 39 | 40 | private final String name; 41 | 42 | private HttpMethod(String name){ 43 | this.name = name; 44 | } 45 | 46 | public static HttpMethod valueOf(String verb){ 47 | return REGISTRY.computeIfAbsent(verb, HttpMethod::new); 48 | } 49 | 50 | public Set all(){ 51 | return new HashSet<>(REGISTRY.values()); 52 | } 53 | 54 | public String name() { 55 | return name; 56 | } 57 | 58 | @Override 59 | public String toString() { 60 | return name; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /pnx-test-starter-http/src/main/java/com/pnxtest/http/internal/HttpParsingException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.http.internal; 23 | 24 | public class HttpParsingException extends HttpException { 25 | private final String originalBody; 26 | 27 | public HttpParsingException(String originalBody, Exception e) { 28 | super(e); 29 | this.originalBody = originalBody; 30 | } 31 | 32 | public String getOriginalBody() { 33 | return originalBody; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /pnx-test-starter-http/src/main/java/com/pnxtest/http/internal/HttpRequestImplWithoutBody.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.http.internal; 23 | 24 | import com.pnxtest.http.HttpConfig; 25 | import com.pnxtest.http.api.Body; 26 | import com.pnxtest.http.api.GetRequest; 27 | 28 | import java.util.Optional; 29 | 30 | public class HttpRequestImplWithoutBody extends BaseRequest implements GetRequest { 31 | public HttpRequestImplWithoutBody(HttpConfig httpConfig, HttpMethod method, String url) { 32 | super(httpConfig, method, url); 33 | } 34 | 35 | @Override 36 | public Optional getBody() { 37 | return Optional.empty(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /pnx-test-starter-http/src/main/java/com/pnxtest/http/internal/InputStreamPart.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.http.internal; 23 | 24 | import java.io.InputStream; 25 | 26 | public class InputStreamPart extends BodyPart { 27 | private String fileName; 28 | 29 | InputStreamPart(String name, InputStream value) { 30 | super(value, name, null); 31 | } 32 | 33 | InputStreamPart(String name, InputStream value, String contentType) { 34 | super(value, name, contentType); 35 | } 36 | 37 | InputStreamPart(String name, InputStream value, String contentType, String fileName) { 38 | super(value, name, contentType); 39 | this.fileName = fileName; 40 | } 41 | 42 | @Override 43 | public String getFileName() { 44 | return fileName; 45 | } 46 | 47 | @Override 48 | public boolean isFile() { 49 | return true; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /pnx-test-starter-http/src/main/java/com/pnxtest/http/internal/MappedResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.http.internal; 23 | 24 | class MappedResponse extends BaseResponse { 25 | private final V body; 26 | 27 | public MappedResponse(BaseResponse response, V body) { 28 | super(response); 29 | this.body = body; 30 | } 31 | 32 | @Override 33 | public V getBody() { 34 | return body; 35 | } 36 | } -------------------------------------------------------------------------------- /pnx-test-starter-http/src/main/java/com/pnxtest/http/internal/MultipartMode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.http.internal; 23 | 24 | public enum MultipartMode { 25 | /** RFC 822, RFC 2045, RFC 2046 compliant */ 26 | STRICT, 27 | /** browser-compatible mode, i.e. only write Content-Disposition; use content charset */ 28 | BROWSER_COMPATIBLE, 29 | /** RFC 6532 compliant */ 30 | RFC6532 31 | } 32 | -------------------------------------------------------------------------------- /pnx-test-starter-http/src/main/java/com/pnxtest/http/internal/ObjectResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.http.internal; 23 | 24 | import com.pnxtest.http.api.ObjectMapper; 25 | import com.pnxtest.http.api.RawResponse; 26 | 27 | import java.util.Optional; 28 | import java.util.function.Function; 29 | 30 | 31 | class ObjectResponse extends BaseResponse { 32 | private final T body; 33 | private final ObjectMapper om; 34 | 35 | ObjectResponse(ObjectMapper om, RawResponse response, Class to) { 36 | super(response); 37 | this.om = om; 38 | this.body = readBody(response) 39 | .map(s -> getBody(s, e -> om.readValue(e, to))) 40 | .orElse(null); 41 | } 42 | 43 | ObjectResponse(ObjectMapper om, RawResponse response, GenericType to){ 44 | super(response); 45 | this.om = om; 46 | this.body = readBody(response) 47 | .map(s -> getBody(s, e -> om.readValue(e, to))) 48 | .orElse(null); 49 | } 50 | 51 | private Optional readBody(RawResponse response) { 52 | if(!response.hasContent()){ 53 | return Optional.empty(); 54 | } 55 | return Optional.of(response.getContentAsString()); 56 | } 57 | 58 | private T getBody(String b, Function func){ 59 | try { 60 | return func.apply(b); 61 | } catch (RuntimeException e) { 62 | setParsingException(b, e); 63 | return null; 64 | } 65 | } 66 | 67 | @Override 68 | public T getBody() { 69 | return body; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /pnx-test-starter-http/src/main/java/com/pnxtest/http/internal/ParamPart.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.http.internal; 23 | 24 | class ParamPart extends BodyPart { 25 | ParamPart(String name, String value) { 26 | this(name, value, null); 27 | } 28 | 29 | ParamPart(String name, String value, String contentType) { 30 | super(value, name, contentType); 31 | } 32 | 33 | @Override 34 | public boolean isFile() { 35 | return false; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /pnx-test-starter-http/src/main/java/com/pnxtest/http/internal/Proxy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.http.internal; 23 | 24 | public class Proxy { 25 | private final String host; 26 | private final Integer port; 27 | private final String username; 28 | private final String password; 29 | 30 | public Proxy(String host, Integer port){ 31 | this(host, port, null, null); 32 | } 33 | 34 | public Proxy(String host, Integer port, String username, String password) { 35 | this.host = host; 36 | this.port = port; 37 | this.username = username; 38 | this.password = password; 39 | } 40 | 41 | public String getHost() { 42 | return host; 43 | } 44 | 45 | public Integer getPort() { 46 | return port; 47 | } 48 | 49 | public String getUsername() { 50 | return username; 51 | } 52 | 53 | public String getPassword() { 54 | return password; 55 | } 56 | 57 | public boolean isAuthenticated() { 58 | return username != null && password != null; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /pnx-test-starter-http/src/main/java/com/pnxtest/http/internal/RawResponseBase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.http.internal; 23 | 24 | import com.pnxtest.http.HttpConfig; 25 | import com.pnxtest.http.api.RawResponse; 26 | 27 | import java.util.regex.Matcher; 28 | import java.util.regex.Pattern; 29 | 30 | abstract class RawResponseBase implements RawResponse { 31 | 32 | private static final Pattern CHARSET_PATTERN = Pattern.compile("(?i)\\bcharset=\\s*\"?([^\\s;\"]*)"); 33 | protected HttpConfig httpConfig; 34 | 35 | protected RawResponseBase(HttpConfig httpConfig){ 36 | this.httpConfig = httpConfig; 37 | } 38 | 39 | protected String getCharSet() { 40 | String contentType = getContentType(); 41 | String responseCharset = getCharsetFromContentType(contentType); 42 | if (responseCharset != null && !responseCharset.trim().equals("")) { 43 | return responseCharset; 44 | } 45 | return httpConfig.getResponseEncoding().name(); 46 | } 47 | 48 | private String getCharsetFromContentType(String contentType) { 49 | if (contentType == null) { 50 | return null; 51 | } 52 | 53 | Matcher m = CHARSET_PATTERN.matcher(contentType); 54 | if (m.find()) { 55 | return m.group(1).trim().toUpperCase(); 56 | } 57 | return null; 58 | } 59 | 60 | @Override 61 | public HttpConfig getHttpConfig() { 62 | return httpConfig; 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /pnx-test-starter-http/src/main/java/com/pnxtest/http/internal/RequestOptions.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.http.internal; 23 | 24 | import com.pnxtest.http.HttpConfig; 25 | import org.apache.http.HttpHost; 26 | import org.apache.http.client.config.RequestConfig; 27 | 28 | class RequestOptions { 29 | 30 | static RequestConfig toRequestConfig(HttpConfig httpConfig) { 31 | int connectionTimeout = httpConfig.getConnectionTimeout(); 32 | int socketTimeout = httpConfig.getSocketTimeout(); 33 | HttpHost proxy = toApacheProxy(httpConfig.getProxy()); 34 | return RequestConfig.custom() 35 | .setConnectTimeout(connectionTimeout) 36 | .setSocketTimeout(socketTimeout) 37 | //.setConnectionRequestTimeout(socketTimeout) 38 | .setProxy(proxy) 39 | .build(); 40 | } 41 | 42 | public static HttpHost toApacheProxy(Proxy proxy){ 43 | if(proxy == null){ 44 | return null; 45 | } 46 | return new HttpHost(proxy.getHost(), proxy.getPort()); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /pnx-test-starter-http/src/main/java/com/pnxtest/http/internal/SimpleResponse.java: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (c) 2020-2021 4 | * This file is part of PnxTest framework. 5 | * 6 | * PnxTest is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero Public License version 3 as 8 | * published by the Free Software Foundation 9 | * 10 | * PnxTest is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero Public License 16 | * along with PnxTest. If not, see . 17 | * 18 | * For more information, please contact the author at this address: 19 | * chen.baker@gmail.com 20 | * 21 | */ 22 | 23 | package com.pnxtest.http.internal; 24 | 25 | class SimpleResponse extends BaseResponse { 26 | private final T body; 27 | 28 | SimpleResponse(T body, BaseResponse response) { 29 | super(response); 30 | this.body = body; 31 | } 32 | 33 | @Override 34 | public T getBody() { 35 | return body; 36 | } 37 | } -------------------------------------------------------------------------------- /pnx-test-starter-http/src/main/java/com/pnxtest/http/internal/StreamBody.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.http.internal; 23 | 24 | import org.apache.http.entity.ContentType; 25 | import org.apache.http.entity.mime.content.InputStreamBody; 26 | 27 | import java.io.IOException; 28 | import java.io.InputStream; 29 | import java.io.OutputStream; 30 | 31 | class StreamBody extends InputStreamBody { 32 | private final long length; 33 | private final String name; 34 | private final String fileName; 35 | 36 | public StreamBody(InputStream in, 37 | ContentType contentType, 38 | String fileName, 39 | String fieldName) { 40 | super(in, contentType, fileName); 41 | this.fileName = fileName; 42 | try { 43 | this.name = fieldName; 44 | this.length = in.available(); 45 | }catch (IOException e){ 46 | throw new HttpException(e); 47 | } 48 | } 49 | 50 | @Override 51 | public void writeTo(OutputStream out) throws IOException { 52 | super.writeTo(out); 53 | } 54 | } -------------------------------------------------------------------------------- /pnx-test-starter-http/src/main/java/com/pnxtest/http/internal/StringResponse.java: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (c) 2020-2021 4 | * This file is part of PnxTest framework. 5 | * 6 | * PnxTest is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero Public License version 3 as 8 | * published by the Free Software Foundation 9 | * 10 | * PnxTest is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero Public License 16 | * along with PnxTest. If not, see . 17 | * 18 | * For more information, please contact the author at this address: 19 | * chen.baker@gmail.com 20 | * 21 | */ 22 | 23 | package com.pnxtest.http.internal; 24 | 25 | import com.pnxtest.http.api.RawResponse; 26 | 27 | class StringResponse extends BaseResponse { 28 | private String body; 29 | 30 | public StringResponse(RawResponse response, String encoding) { 31 | super(response); 32 | body = response.getContentAsString(encoding); 33 | } 34 | 35 | @Override 36 | public String getBody() { 37 | return body; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /pnx-test-starter-http/src/main/java/com/pnxtest/http/internal/SyncIdleConnectionMonitorThread.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021 3 | * This file is part of PnxTest framework. 4 | * 5 | * PnxTest is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero Public License version 3 as 7 | * published by the Free Software Foundation 8 | * 9 | * PnxTest is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero Public License 15 | * along with PnxTest. If not, see . 16 | * 17 | * For more information, please contact the author at this address: 18 | * chen.baker@gmail.com 19 | * 20 | */ 21 | 22 | package com.pnxtest.http.internal; 23 | 24 | import org.apache.http.conn.HttpClientConnectionManager; 25 | 26 | import java.util.concurrent.TimeUnit; 27 | 28 | class SyncIdleConnectionMonitorThread extends Thread { 29 | 30 | private final HttpClientConnectionManager connMgr; 31 | 32 | public SyncIdleConnectionMonitorThread(HttpClientConnectionManager connMgr) { 33 | super(); 34 | super.setDaemon(true); 35 | this.connMgr = connMgr; 36 | } 37 | 38 | @Override 39 | public void run() { 40 | try { 41 | while (!Thread.currentThread().isInterrupted()) { 42 | synchronized (this) { 43 | wait(5000); 44 | // Close expired connections 45 | connMgr.closeExpiredConnections(); 46 | // Optionally, close connections 47 | // that have been idle longer than 30 sec 48 | connMgr.closeIdleConnections(30, TimeUnit.SECONDS); 49 | } 50 | } 51 | } catch (InterruptedException ex) { 52 | // terminate 53 | } 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /pnx-test-starter-parent/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 23 | 24 | 26 | 4.0.0 27 | 28 | 29 | com.pnxtest 30 | pnx-test-dependencies 31 | 1.0.2 32 | ../pnx-test-dependencies 33 | 34 | 35 | pnx-test-starter-parent 36 | pom 37 | pnx-test-starter-parent 38 | Parent pom providing dependency and plugin management for applications built with Maven 39 | 40 | 41 | 1.8 42 | 1.8 43 | UTF-8 44 | UTF-8 45 | 46 | 47 | 48 | 49 | 50 | com.pnxtest 51 | pnx-test-dependencies 52 | 1.0.2 53 | pom 54 | import 55 | 56 | 57 | 58 | 59 | --------------------------------------------------------------------------------