deserializer = (json, typeOfT, context) -> json == null ? null : new Date(json.getAsLong());
18 |
19 | public GsonHepler() {
20 | }
21 |
22 | public static Gson getGson() {
23 | return getGson(FieldNamingPolicy.IDENTITY);
24 | }
25 |
26 | public static Gson getGson(FieldNamingPolicy fieldNamingPolicy) {
27 | if (gsons.containsKey(fieldNamingPolicy)) {
28 | return gsons.get(fieldNamingPolicy);
29 | } else {
30 | Gson gson = (new GsonBuilder()).setFieldNamingPolicy(fieldNamingPolicy).registerTypeAdapter(Date.class, serializer).registerTypeAdapter(Date.class, deserializer).create();
31 | synchronized (gsons) {
32 | gsons.put(fieldNamingPolicy, gson);
33 | return gson;
34 | }
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/hrun4j-cli/src/main/java/vip/lematech/hrun4j/cli/service/IProjectGenerator.java:
--------------------------------------------------------------------------------
1 | package vip.lematech.hrun4j.cli.service;
2 |
3 | import vip.lematech.hrun4j.model.scaffolding.ProjectInfo;
4 |
5 | /**
6 | * website https://www.lematech.vip/
7 | * @author lematech@foxmail.com
8 | * @version 1.0.1
9 | */
10 | public interface IProjectGenerator {
11 |
12 | /**
13 | * Generate Maven springboot project scaffolding
14 | *
15 | * @param projectRoot project root
16 | * @param projectInfo project info
17 | */
18 | void springbootGenerator(String projectRoot, ProjectInfo projectInfo);
19 |
20 | /**
21 | * Hrun4j CLi dependency generation
22 | *
23 | * @param projectRoot project root
24 | * @param projectName project info
25 | */
26 | void cliGenerator(String projectRoot, String projectName);
27 | /**
28 | * Hrun4j POM dependency generation
29 | * @param projectRoot project root
30 | * @param projectInfo project info
31 | */
32 | void pomGenerator(String projectRoot, ProjectInfo projectInfo);
33 | }
34 |
--------------------------------------------------------------------------------
/hrun4j-cli/src/main/java/vip/lematech/hrun4j/model/har/Har.java:
--------------------------------------------------------------------------------
1 | /**
2 | * har - HAR file reader, writer and viewer
3 | * Copyright (c) 2014-2016, Sandeep Gupta
4 | *
5 | * http://sangupta.com/projects/har
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an "AS IS" BASIS,
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | * See the License for the specific language governing permissions and
17 | * limitations under the License.
18 | */
19 |
20 | package vip.lematech.hrun4j.model.har;
21 |
22 | import lombok.Data;
23 |
24 | /**
25 | * Top level model object for the HAR file
26 | * website https://www.lematech.vip/
27 | * @author lematech@foxmail.com
28 | * @version 1.0.1
29 | */
30 |
31 | @Data
32 | public class Har {
33 |
34 | private HarLog log;
35 | @Override
36 | public String toString() {
37 | return "Har [log=" + log + "]";
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/hrun4j-cli/src/main/java/vip/lematech/hrun4j/model/har/HarBaseModel.java:
--------------------------------------------------------------------------------
1 | package vip.lematech.hrun4j.model.har;
2 |
3 | import lombok.Data;
4 |
5 | /**
6 | * website https://www.lematech.vip/
7 | * @author lematech@foxmail.com
8 | * @version 1.0.1
9 | */
10 | @Data
11 | public class HarBaseModel {
12 | String name;
13 |
14 | String value;
15 |
16 | String comment;
17 | }
18 |
--------------------------------------------------------------------------------
/hrun4j-cli/src/main/java/vip/lematech/hrun4j/model/har/HarCache.java:
--------------------------------------------------------------------------------
1 | /**
2 | * har - HAR file reader, writer and viewer
3 | * Copyright (c) 2014-2016, Sandeep Gupta
4 | *
5 | * http://sangupta.com/projects/har
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an "AS IS" BASIS,
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | * See the License for the specific language governing permissions and
17 | * limitations under the License.
18 | */
19 |
20 | package vip.lematech.hrun4j.model.har;
21 |
22 | import lombok.Data;
23 |
24 | /**
25 | * Request information cached from the browser
26 | * @author sangupta/lematech@foxmail.com
27 | * website https://www.lematech.vip/
28 | * @version 1.0.1
29 | */
30 |
31 | @Data
32 | public class HarCache {
33 |
34 | private HarCacheDetails beforeRequest;
35 |
36 | private HarCacheDetails afterRequest;
37 |
38 | private String comment;
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/hrun4j-cli/src/main/java/vip/lematech/hrun4j/model/har/HarCacheDetails.java:
--------------------------------------------------------------------------------
1 | /**
2 | * har - HAR file reader, writer and viewer
3 | * Copyright (c) 2014-2016, Sandeep Gupta
4 | *
5 | * http://sangupta.com/projects/har
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an "AS IS" BASIS,
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | * See the License for the specific language governing permissions and
17 | * limitations under the License.
18 | */
19 |
20 | package vip.lematech.hrun4j.model.har;
21 |
22 | import lombok.Data;
23 |
24 | /**
25 | * A detailed list of buffer information
26 | * @author sangupta/lematech@foxmail.com
27 | * @version 1.0.1
28 | */
29 |
30 | @Data
31 | public class HarCacheDetails {
32 |
33 | private String expires;
34 |
35 | private String lastAccess;
36 |
37 | private String etag;
38 |
39 | private String hitCount;
40 |
41 | private String comment;
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/hrun4j-cli/src/main/java/vip/lematech/hrun4j/model/har/HarContent.java:
--------------------------------------------------------------------------------
1 | /**
2 | * har - HAR file reader, writer and viewer
3 | * Copyright (c) 2014-2016, Sandeep Gupta
4 | *
5 | * http://sangupta.com/projects/har
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an "AS IS" BASIS,
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | * See the License for the specific language governing permissions and
17 | * limitations under the License.
18 | */
19 |
20 | package vip.lematech.hrun4j.model.har;
21 |
22 | import lombok.Data;
23 |
24 | /**
25 | * @author sangupta/lematech@foxmail.com
26 | * website https://www.lematech.vip/
27 | * @version 1.0.1
28 | */
29 |
30 | @Data
31 | public class HarContent {
32 |
33 | private long size;
34 |
35 | private String mimeType;
36 |
37 | private long compression;
38 |
39 | private String text;
40 |
41 | private String comment;
42 |
43 | private String encoding;
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/hrun4j-cli/src/main/java/vip/lematech/hrun4j/model/har/HarCookie.java:
--------------------------------------------------------------------------------
1 | /**
2 | * har - HAR file reader, writer and viewer
3 | * Copyright (c) 2014-2016, Sandeep Gupta
4 | *
5 | * http://sangupta.com/projects/har
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an "AS IS" BASIS,
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | * See the License for the specific language governing permissions and
17 | * limitations under the License.
18 | */
19 |
20 | package vip.lematech.hrun4j.model.har;
21 |
22 | import lombok.Data;
23 |
24 | /**
25 | * @author sangupta/lematech@foxmail.com
26 | * website https://www.lematech.vip/
27 | * @version 1.0.1
28 | */
29 |
30 | @Data
31 | public class HarCookie extends HarBaseModel {
32 |
33 | private String path;
34 |
35 | private String expires;
36 |
37 | private boolean httpOnly;
38 |
39 | private boolean secure;
40 |
41 | @Override
42 | public String toString() {
43 | return "[Cookie: " + this.name + "=" + this.value + "]";
44 | }
45 |
46 | @Override
47 | public int hashCode() {
48 | if (this.name == null) {
49 | return -1;
50 | }
51 |
52 | return this.name.hashCode();
53 | }
54 |
55 | @Override
56 | public boolean equals(Object obj) {
57 | if (!(obj instanceof HarCookie)) {
58 | return false;
59 | }
60 |
61 | if (this.name == null) {
62 | return false;
63 | }
64 |
65 | HarCookie harCookie = (HarCookie) obj;
66 | return this.name.equals(harCookie.name);
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/hrun4j-cli/src/main/java/vip/lematech/hrun4j/model/har/HarCreator.java:
--------------------------------------------------------------------------------
1 | /**
2 | * har - HAR file reader, writer and viewer
3 | * Copyright (c) 2014-2016, Sandeep Gupta
4 | *
5 | * http://sangupta.com/projects/har
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an "AS IS" BASIS,
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | * See the License for the specific language governing permissions and
17 | * limitations under the License.
18 | */
19 |
20 | package vip.lematech.hrun4j.model.har;
21 |
22 | import lombok.Data;
23 |
24 | /**
25 | * HAR file creator and version information
26 | * @author sangupta/lematech@foxmail.com
27 | * website https://www.lematech.vip/
28 | * @version 1.0.1
29 | */
30 |
31 | @Data
32 | public class HarCreator {
33 |
34 | private String name;
35 |
36 | private String version;
37 |
38 | private String comment;
39 |
40 | @Override
41 | public String toString() {
42 | return "[HARCreator: " + this.name + " (" + this.version + ") ]";
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/hrun4j-cli/src/main/java/vip/lematech/hrun4j/model/har/HarEntry.java:
--------------------------------------------------------------------------------
1 | /**
2 | * har - HAR file reader, writer and viewer
3 | * Copyright (c) 2014-2016, Sandeep Gupta
4 | *
5 | * http://sangupta.com/projects/har
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an "AS IS" BASIS,
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | * See the License for the specific language governing permissions and
17 | * limitations under the License.
18 | */
19 |
20 | package vip.lematech.hrun4j.model.har;
21 |
22 | import com.sangupta.jerry.util.UriUtils;
23 | import lombok.Data;
24 |
25 | import java.util.Objects;
26 |
27 | /**
28 | * An array containing all requests, each item of the array is an object composed of the data of a request, sorted according to StartedDateTime
29 | * @author sangupta/lematech@foxmail.com
30 | * website https://www.lematech.vip/
31 | * @version 1.0.1
32 | */
33 |
34 | @Data
35 | public class HarEntry implements Comparable {
36 |
37 | private String pageref;
38 |
39 | private String startedDateTime;
40 |
41 | private double time;
42 |
43 | private HarRequest request;
44 |
45 | private HarResponse response;
46 |
47 | private HarCache cache;
48 |
49 | private HarTiming timings;
50 |
51 | private String serverIPAddress;
52 |
53 | private String connection;
54 |
55 | private String comment;
56 |
57 | @Override
58 | public String toString() {
59 | return request.getMethod() + " " + UriUtils.extractPath(request.getUrl());
60 | }
61 |
62 | @Override
63 | public int compareTo(HarEntry o) {
64 | if (Objects.isNull(o)) {
65 | return -1;
66 | }
67 | return this.startedDateTime.compareTo(o.startedDateTime);
68 | }
69 |
70 | }
71 |
--------------------------------------------------------------------------------
/hrun4j-cli/src/main/java/vip/lematech/hrun4j/model/har/HarHeader.java:
--------------------------------------------------------------------------------
1 | /**
2 | * har - HAR file reader, writer and viewer
3 | * Copyright (c) 2014-2016, Sandeep Gupta
4 | *
5 | * http://sangupta.com/projects/har
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an "AS IS" BASIS,
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | * See the License for the specific language governing permissions and
17 | * limitations under the License.
18 | */
19 |
20 | package vip.lematech.hrun4j.model.har;
21 |
22 | import cn.hutool.core.util.StrUtil;
23 | import lombok.Data;
24 |
25 | /**
26 | * @author sangupta/lematech@foxmail.com
27 | * website https://www.lematech.vip/
28 | * @version 1.0.1
29 | */
30 |
31 | @Data
32 | public class HarHeader extends HarBaseModel {
33 |
34 | @Override
35 | public String toString() {
36 | return "[Header: " + this.name + "=" + this.value + "]";
37 | }
38 |
39 | @Override
40 | public int hashCode() {
41 | if (StrUtil.isEmpty(this.name)) {
42 | return -1;
43 | }
44 | return this.name.hashCode();
45 | }
46 |
47 | @Override
48 | public boolean equals(Object obj) {
49 | if (!(obj instanceof HarHeader)) {
50 | return false;
51 | }
52 |
53 | if (StrUtil.isEmpty(this.name)) {
54 | return false;
55 | }
56 | HarHeader harHeader = (HarHeader) obj;
57 | return this.name.equals(harHeader.name);
58 | }
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/hrun4j-cli/src/main/java/vip/lematech/hrun4j/model/har/HarLog.java:
--------------------------------------------------------------------------------
1 | /**
2 | * har - HAR file reader, writer and viewer
3 | * Copyright (c) 2014-2016, Sandeep Gupta
4 | *
5 | * http://sangupta.com/projects/har
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an "AS IS" BASIS,
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | * See the License for the specific language governing permissions and
17 | * limitations under the License.
18 | */
19 |
20 | package vip.lematech.hrun4j.model.har;
21 |
22 | import lombok.Data;
23 |
24 | import java.util.List;
25 |
26 | /**
27 | * @author sangupta/lematech@foxmail.com
28 | * website https://www.lematech.vip/
29 | * @version 1.0.1
30 | */
31 |
32 | @Data
33 | public class HarLog {
34 |
35 | public static final String DEFAULT_HAR_VERSION = "1.1";
36 |
37 | private String version = DEFAULT_HAR_VERSION;
38 |
39 | private HarCreator creator;
40 |
41 | private HarCreator browser;
42 |
43 | private List pages;
44 |
45 | private List entries;
46 |
47 | private String comment;
48 |
49 | @Override
50 | public String toString() {
51 | return "HarLog [version=" + version + ", creator=" + creator + ", browser=" + browser + ", pages=" + pages + ", entries=" + entries + ", comment=" + comment + "]";
52 | }
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/hrun4j-cli/src/main/java/vip/lematech/hrun4j/model/har/HarPage.java:
--------------------------------------------------------------------------------
1 | /**
2 | * har - HAR file reader, writer and viewer
3 | * Copyright (c) 2014-2016, Sandeep Gupta
4 | *
5 | * http://sangupta.com/projects/har
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an "AS IS" BASIS,
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | * See the License for the specific language governing permissions and
17 | * limitations under the License.
18 | */
19 |
20 | package vip.lematech.hrun4j.model.har;
21 |
22 | import lombok.Data;
23 |
24 | import java.util.List;
25 |
26 | /**
27 | * @author sangupta/lematech@foxmail.com
28 | * website https://www.lematech.vip/
29 | * @version 1.0.1
30 | */
31 |
32 | @Data
33 | public class HarPage {
34 |
35 | private String startedDateTime;
36 |
37 | private String id;
38 |
39 | private String title;
40 |
41 | private HarPageTiming pageTimings;
42 |
43 | private String comment;
44 |
45 | private transient List entries;
46 |
47 | @Override
48 | public String toString() {
49 | return "[Page: " + this.id + " (" + this.title + ") ]";
50 | }
51 |
52 | @Override
53 | public int hashCode() {
54 | if (this.id == null) {
55 | return -1;
56 | }
57 |
58 | return this.id.hashCode();
59 | }
60 |
61 | @Override
62 | public boolean equals(Object obj) {
63 | if (!(obj instanceof HarPage)) {
64 | return false;
65 | }
66 |
67 | if (this.id == null) {
68 | return false;
69 | }
70 |
71 | HarPage harPage = (HarPage) obj;
72 | return this.id.equals(harPage.id);
73 | }
74 |
75 | }
76 |
--------------------------------------------------------------------------------
/hrun4j-cli/src/main/java/vip/lematech/hrun4j/model/har/HarPageTiming.java:
--------------------------------------------------------------------------------
1 | /**
2 | * har - HAR file reader, writer and viewer
3 | * Copyright (c) 2014-2016, Sandeep Gupta
4 | *
5 | * http://sangupta.com/projects/har
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an "AS IS" BASIS,
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | * See the License for the specific language governing permissions and
17 | * limitations under the License.
18 | */
19 |
20 | package vip.lematech.hrun4j.model.har;
21 |
22 |
23 | import lombok.Data;
24 |
25 | /**
26 | * @author sangupta/lematech@foxmail.com
27 | * website https://www.lematech.vip/
28 | * @version 1.0.1
29 | */
30 |
31 | @Data
32 | public class HarPageTiming {
33 |
34 | private double onContentLoad;
35 |
36 | private double onLoad;
37 |
38 | private String comment;
39 |
40 | @Override
41 | public String toString() {
42 | return "HarPageTiming [onContentLoad=" + onContentLoad + ", onLoad=" + onLoad + ", comment=" + comment + "]";
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/hrun4j-cli/src/main/java/vip/lematech/hrun4j/model/har/HarPostData.java:
--------------------------------------------------------------------------------
1 | /**
2 | * har - HAR file reader, writer and viewer
3 | * Copyright (c) 2014-2016, Sandeep Gupta
4 | *
5 | * http://sangupta.com/projects/har
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an "AS IS" BASIS,
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | * See the License for the specific language governing permissions and
17 | * limitations under the License.
18 | */
19 |
20 | package vip.lematech.hrun4j.model.har;
21 |
22 | import lombok.Data;
23 |
24 | import java.util.List;
25 |
26 | /**
27 | * @author sangupta/lematech@foxmail.com
28 | * website https://www.lematech.vip/
29 | * @version 1.0.1
30 | */
31 |
32 | @Data
33 | public class HarPostData {
34 |
35 | private String mimeType;
36 |
37 | private List params;
38 |
39 | private String text;
40 |
41 | private String comment;
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/hrun4j-cli/src/main/java/vip/lematech/hrun4j/model/har/HarPostParam.java:
--------------------------------------------------------------------------------
1 | /**
2 | * har - HAR file reader, writer and viewer
3 | * Copyright (c) 2014-2016, Sandeep Gupta
4 | *
5 | * http://sangupta.com/projects/har
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an "AS IS" BASIS,
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | * See the License for the specific language governing permissions and
17 | * limitations under the License.
18 | */
19 |
20 | package vip.lematech.hrun4j.model.har;
21 |
22 |
23 | import lombok.Data;
24 |
25 | /**
26 | * @author sangupta/lematech@foxmail.com
27 | * website https://www.lematech.vip/
28 | * @version 1.0.1
29 | */
30 |
31 | @Data
32 | public class HarPostParam extends HarBaseModel {
33 |
34 | private String fileName;
35 |
36 | private String contentType;
37 |
38 | @Override
39 | public String toString() {
40 | return "[Post Param: " + this.name + "=" + this.value + "]";
41 | }
42 |
43 | @Override
44 | public int hashCode() {
45 | if (this.name == null) {
46 | return -1;
47 | }
48 |
49 | return this.name.hashCode();
50 | }
51 |
52 | @Override
53 | public boolean equals(Object obj) {
54 | if (!(obj instanceof HarPostParam)) {
55 | return false;
56 | }
57 |
58 | if (this.name == null) {
59 | return false;
60 | }
61 |
62 | HarPostParam harPostParam = (HarPostParam) obj;
63 | return this.name.equals(harPostParam.name);
64 | }
65 |
66 | }
67 |
--------------------------------------------------------------------------------
/hrun4j-cli/src/main/java/vip/lematech/hrun4j/model/har/HarQueryParm.java:
--------------------------------------------------------------------------------
1 | /**
2 | * har - HAR file reader, writer and viewer
3 | * Copyright (c) 2014-2016, Sandeep Gupta
4 | *
5 | * http://sangupta.com/projects/har
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an "AS IS" BASIS,
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | * See the License for the specific language governing permissions and
17 | * limitations under the License.
18 | */
19 |
20 | package vip.lematech.hrun4j.model.har;
21 |
22 | import lombok.Data;
23 |
24 | /**
25 | * @author sangupta/lematech@foxmail.com
26 | * website https://www.lematech.vip/
27 | * @version 1.0.1
28 | */
29 |
30 | @Data
31 | public class HarQueryParm extends HarBaseModel {
32 |
33 |
34 | @Override
35 | public String toString() {
36 | return "[Query Param: " + this.name + "=" + this.value + "]";
37 | }
38 |
39 | @Override
40 | public int hashCode() {
41 | if (this.name == null) {
42 | return -1;
43 | }
44 |
45 | return this.name.hashCode();
46 | }
47 |
48 | @Override
49 | public boolean equals(Object obj) {
50 | if (!(obj instanceof HarQueryParm)) {
51 | return false;
52 | }
53 |
54 | if (this.name == null) {
55 | return false;
56 | }
57 |
58 | HarQueryParm harQueryParm = (HarQueryParm) obj;
59 | return this.name.equals(harQueryParm.name);
60 | }
61 |
62 | }
63 |
--------------------------------------------------------------------------------
/hrun4j-cli/src/main/java/vip/lematech/hrun4j/model/har/HarRequest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * har - HAR file reader, writer and viewer
3 | * Copyright (c) 2014-2016, Sandeep Gupta
4 | *
5 | * http://sangupta.com/projects/har
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an "AS IS" BASIS,
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | * See the License for the specific language governing permissions and
17 | * limitations under the License.
18 | */
19 |
20 | package vip.lematech.hrun4j.model.har;
21 |
22 | import lombok.Data;
23 |
24 | import java.util.List;
25 |
26 | /**
27 | * HAR request information
28 | * @author sangupta/lematech@foxmail.com
29 | * website https://www.lematech.vip/
30 | * @version 1.0.1
31 | */
32 |
33 | @Data
34 | public class HarRequest {
35 |
36 | private String method;
37 |
38 | private String url;
39 |
40 | private String httpVersion;
41 |
42 | private List cookies;
43 |
44 | private List headers;
45 |
46 | private List queryString;
47 |
48 | private HarPostData postData;
49 |
50 | private long headersSize;
51 |
52 | private long bodySize;
53 |
54 | private String comment;
55 |
56 | @Override
57 | public String toString() {
58 | return this.method + " " + this.url + " " + this.httpVersion;
59 | }
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/hrun4j-cli/src/main/java/vip/lematech/hrun4j/model/har/HarResponse.java:
--------------------------------------------------------------------------------
1 | /**
2 | * har - HAR file reader, writer and viewer
3 | * Copyright (c) 2014-2016, Sandeep Gupta
4 | *
5 | * http://sangupta.com/projects/har
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an "AS IS" BASIS,
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | * See the License for the specific language governing permissions and
17 | * limitations under the License.
18 | */
19 |
20 | package vip.lematech.hrun4j.model.har;
21 |
22 | import lombok.Data;
23 |
24 | import java.util.List;
25 |
26 | /**
27 | * HAR response information
28 | * @author sangupta/lematech@foxmail.com
29 | * website https://www.lematech.vip/
30 | * @version 1.0.1
31 | */
32 |
33 | @Data
34 | public class HarResponse {
35 |
36 | private int status;
37 |
38 | private String statusText;
39 |
40 | private String httpVersion;
41 |
42 | private List headers;
43 |
44 | private List cookies;
45 |
46 | private HarContent content;
47 |
48 | private String redirectURL;
49 |
50 | private long headersSize;
51 |
52 | private long bodySize;
53 |
54 | @Override
55 | public String toString() {
56 | return "HTTP " + this.status + " (" + this.statusText + ")";
57 | }
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/hrun4j-cli/src/main/java/vip/lematech/hrun4j/model/har/HarTiming.java:
--------------------------------------------------------------------------------
1 | /**
2 | * har - HAR file reader, writer and viewer
3 | * Copyright (c) 2014-2016, Sandeep Gupta
4 | *
5 | * http://sangupta.com/projects/har
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an "AS IS" BASIS,
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | * See the License for the specific language governing permissions and
17 | * limitations under the License.
18 | */
19 |
20 | package vip.lematech.hrun4j.model.har;
21 |
22 |
23 | /**
24 | *
25 | * The time between sending a request and receiving a response is measured in milliseconds
26 | * @author sangupta/lematech@foxmail.com
27 | * website https://www.lematech.vip/
28 | * @version 1.0.1
29 | */
30 | public class HarTiming {
31 |
32 | public double blocked;
33 |
34 | public double dns;
35 |
36 | public double connect;
37 |
38 | public double send;
39 |
40 | public double wait;
41 |
42 | public double receive;
43 |
44 | public double ssl;
45 |
46 | public String comment;
47 |
48 |
49 | @Override
50 | public String toString() {
51 | return "HarTiming [blocked=" + blocked + ", dns=" + dns + ", connect=" + connect + ", send=" + send + ", wait=" + wait + ", receive=" + receive + ", ssl=" + ssl + ", comment=" + comment + "]";
52 | }
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/hrun4j-cli/src/main/java/vip/lematech/hrun4j/model/postman/PostmanCollection.java:
--------------------------------------------------------------------------------
1 | package vip.lematech.hrun4j.model.postman;
2 |
3 | import lombok.Data;
4 |
5 | import java.util.List;
6 |
7 | /**
8 | * website https://www.lematech.vip/
9 | * @author chenfanghang
10 | * @version 1.0.1
11 | */
12 | @Data
13 | public class PostmanCollection {
14 |
15 | private PostmanCollectionInfo info;
16 | private List item;
17 | private List variable;
18 | }
19 |
--------------------------------------------------------------------------------
/hrun4j-cli/src/main/java/vip/lematech/hrun4j/model/postman/PostmanCollectionInfo.java:
--------------------------------------------------------------------------------
1 | package vip.lematech.hrun4j.model.postman;
2 |
3 | import com.alibaba.fastjson.annotation.JSONField;
4 | import lombok.Data;
5 |
6 | /**
7 | * website https://www.lematech.vip/
8 | * @author chenfanghang
9 | * @version 1.0.1
10 | */
11 | @Data
12 | public class PostmanCollectionInfo {
13 |
14 | @JSONField(name = "_postman_id")
15 | private String postmanId;
16 | private String name;
17 | private String schema;
18 | }
19 |
--------------------------------------------------------------------------------
/hrun4j-cli/src/main/java/vip/lematech/hrun4j/model/postman/PostmanEvent.java:
--------------------------------------------------------------------------------
1 | package vip.lematech.hrun4j.model.postman;
2 |
3 | import lombok.Data;
4 |
5 | /**
6 | * website https://www.lematech.vip/
7 | * @author chenfanghang
8 | * @version 1.0.1
9 | */
10 | @Data
11 | public class PostmanEvent {
12 | private String listen;
13 | private PostmanScript script;
14 | }
15 |
--------------------------------------------------------------------------------
/hrun4j-cli/src/main/java/vip/lematech/hrun4j/model/postman/PostmanItem.java:
--------------------------------------------------------------------------------
1 | package vip.lematech.hrun4j.model.postman;
2 |
3 | import lombok.Data;
4 |
5 | import java.util.List;
6 |
7 | /**
8 | * website https://www.lematech.vip/
9 | * @author chenfanghang
10 | * @version 1.0.1
11 | */
12 | @Data
13 | public class PostmanItem {
14 | private String name;
15 | private List event;
16 | private PostmanRequest request;
17 | private List item;
18 | private List response;
19 | }
20 |
--------------------------------------------------------------------------------
/hrun4j-cli/src/main/java/vip/lematech/hrun4j/model/postman/PostmanKeyValue.java:
--------------------------------------------------------------------------------
1 | package vip.lematech.hrun4j.model.postman;
2 |
3 | import lombok.Data;
4 |
5 | /**
6 | * website https://www.lematech.vip/
7 | * @author chenfanghang
8 | * @version 1.0.1
9 | */
10 | @Data
11 | public class PostmanKeyValue {
12 | private String key;
13 | private String value;
14 | private String type;
15 | private String description;
16 | private String contentType;
17 |
18 | public PostmanKeyValue() {
19 | }
20 |
21 | public PostmanKeyValue(String key, String value) {
22 | this.key = key;
23 | this.value = value;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/hrun4j-cli/src/main/java/vip/lematech/hrun4j/model/postman/PostmanRequest.java:
--------------------------------------------------------------------------------
1 | package vip.lematech.hrun4j.model.postman;
2 |
3 | import com.alibaba.fastjson.JSONObject;
4 | import lombok.Data;
5 |
6 | import java.util.List;
7 |
8 | /**
9 | * website https://www.lematech.vip/
10 | * @author chenfanghang
11 | * @version 1.0.1
12 | */
13 | @Data
14 | public class PostmanRequest {
15 |
16 | private String method;
17 | private String schema;
18 | private List header;
19 | private JSONObject body;
20 | private JSONObject auth;
21 | private PostmanUrl url;
22 | private String description;
23 | }
24 |
--------------------------------------------------------------------------------
/hrun4j-cli/src/main/java/vip/lematech/hrun4j/model/postman/PostmanRequestBodyModeEnum.java:
--------------------------------------------------------------------------------
1 | package vip.lematech.hrun4j.model.postman;
2 |
3 | /**
4 | * website https://www.lematech.vip/
5 | * @author chenfanghang
6 | * @version 1.0.1
7 | */
8 | public enum PostmanRequestBodyModeEnum {
9 |
10 | RAW("raw"), FORM_DATA("formdata"), URLENCODED("urlencoded"), FILE("file");
11 |
12 | private String value;
13 |
14 | PostmanRequestBodyModeEnum(String value) {
15 | this.value = value;
16 | }
17 |
18 | public String value() {
19 | return this.value;
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/hrun4j-cli/src/main/java/vip/lematech/hrun4j/model/postman/PostmanResponse.java:
--------------------------------------------------------------------------------
1 | package vip.lematech.hrun4j.model.postman;
2 |
3 |
4 | import lombok.Data;
5 |
6 | import java.util.List;
7 |
8 | /**
9 | * website https://www.lematech.vip/
10 | * @author chenfanghang
11 | * @version 1.0.1
12 | */
13 | @Data
14 | public class PostmanResponse {
15 | private String name;
16 | private String status;
17 | private String code;
18 | private String _postman_previewlanguage;
19 | private List header;
20 | private String body;
21 | }
22 |
--------------------------------------------------------------------------------
/hrun4j-cli/src/main/java/vip/lematech/hrun4j/model/postman/PostmanScript.java:
--------------------------------------------------------------------------------
1 | package vip.lematech.hrun4j.model.postman;
2 |
3 | import lombok.Data;
4 |
5 | import java.util.List;
6 |
7 | /**
8 | * website https://www.lematech.vip/
9 | * @author chenfanghang
10 | * @version 1.0.1
11 | */
12 | @Data
13 | public class PostmanScript {
14 | private List exec;
15 | private String type;
16 | }
17 |
--------------------------------------------------------------------------------
/hrun4j-cli/src/main/java/vip/lematech/hrun4j/model/postman/PostmanUrl.java:
--------------------------------------------------------------------------------
1 | package vip.lematech.hrun4j.model.postman;
2 |
3 | import lombok.Data;
4 |
5 | import java.util.List;
6 |
7 | /**
8 | * website https://www.lematech.vip/
9 | * @author chenfanghang
10 | * @version 1.0.1
11 | */
12 | @Data
13 | public class PostmanUrl {
14 |
15 | private String raw;
16 | private String protocol;
17 | private List host;
18 | private String port;
19 | private List path;
20 | private List query;
21 | }
22 |
--------------------------------------------------------------------------------
/hrun4j-cli/src/main/java/vip/lematech/hrun4j/model/scaffolding/ApplicationInfo.java:
--------------------------------------------------------------------------------
1 | package vip.lematech.hrun4j.model.scaffolding;
2 |
3 | import lombok.AllArgsConstructor;
4 | import lombok.Data;
5 | import lombok.NoArgsConstructor;
6 |
7 | /**
8 | * website https://www.lematech.vip/
9 | * @author lematech@foxmail.com
10 | * @version 1.0.1
11 | */
12 |
13 | @Data
14 | @NoArgsConstructor
15 | @AllArgsConstructor
16 | public class ApplicationInfo {
17 | private String packageName;
18 | private String className;
19 | }
20 |
--------------------------------------------------------------------------------
/hrun4j-cli/src/main/java/vip/lematech/hrun4j/model/scaffolding/ProjectInfo.java:
--------------------------------------------------------------------------------
1 | package vip.lematech.hrun4j.model.scaffolding;
2 |
3 | import lombok.AllArgsConstructor;
4 | import lombok.Data;
5 | import lombok.NoArgsConstructor;
6 |
7 | /**
8 | * website https://www.lematech.vip/
9 | * @author lematech@foxmail.com
10 | * @version 1.0.1
11 | */
12 |
13 | @Data
14 | @NoArgsConstructor
15 | @AllArgsConstructor
16 | public class ProjectInfo {
17 | private String groupId;
18 | private String artifactId;
19 | private String version;
20 | private String name;
21 | private String description;
22 | }
23 |
--------------------------------------------------------------------------------
/hrun4j-cli/src/main/resources/META-INF/MANIFEST.MF:
--------------------------------------------------------------------------------
1 | Manifest-Version: 1.0
2 | Main-Class: vip.lematech.hrun4j.Hrun4j
3 |
4 |
--------------------------------------------------------------------------------
/hrun4j-cli/src/main/resources/vm/scaffold/hrun4j/cli/Hrun4j.vm:
--------------------------------------------------------------------------------
1 | #!/bin/java bsh.Interpreter
2 | print("hrun4j.bsh文件所在路径即为项目工程路径");
3 | print("你好,欢迎使用hrun4j!");
4 | print("官网:http://www.lematech.vip");
5 | print("微信公众号:lematech");
6 | print("技术交流微信:wytest");
--------------------------------------------------------------------------------
/hrun4j-cli/src/main/resources/vm/scaffold/hrun4j/cli/apis/get.vm:
--------------------------------------------------------------------------------
1 | name: Postman Echo GET Request
2 | base_url: https://postman-echo.com
3 | variables:
4 | website: http://lematech.vip_api
5 | project: hrun4j_api
6 | author: lematech_api
7 | request:
8 | url: /get?website=${website}&project=${project}&author=${author}
9 | method: GET
--------------------------------------------------------------------------------
/hrun4j-cli/src/main/resources/vm/scaffold/hrun4j/cli/apis/postFormData.vm:
--------------------------------------------------------------------------------
1 | name: Postman Echo POST Raw Text Request
2 | base_url: http://lematech.vip
3 | variables:
4 | website: http://lematech.vip_api
5 | project: hrun4j_api
6 | author: lematech_api
7 | request:
8 | url: /post
9 | method: POST
10 | headers:
11 | data:
12 | website: ${website}
13 | project: ${project}
14 | author: ${author}
--------------------------------------------------------------------------------
/hrun4j-cli/src/main/resources/vm/scaffold/hrun4j/cli/apis/postRawText.vm:
--------------------------------------------------------------------------------
1 | name: Postman Echo POST Raw Text Request
2 | base_url: https://postman-echo.com
3 | variables:
4 | data: "This is expected to be sent back as part of response body._api"
5 | request:
6 | url: /post
7 | method: POST
8 | data: ${data}
--------------------------------------------------------------------------------
/hrun4j-cli/src/main/resources/vm/scaffold/hrun4j/cli/bsh/test.vm:
--------------------------------------------------------------------------------
1 | #!/bin/java bsh.Interpreter
2 |
3 | 1>2;
4 | foo = "Foo";
5 | four = (2 + 2)*2/2;
6 | print( foo + " = " + four );
7 | for (i=0; i<5; i++)
8 | print(i);
9 | int multiply(a, b)
10 | {
11 | return a*b;
12 | }
13 | result = multiply(12,14);
14 | print(result);//打印出168
15 |
16 | //import RequestEntity;
17 | //print($aaa);
18 |
19 | print("请求参数:"+$REQUEST);
20 | print("响应参数:"+$RESPONSE);
21 | print("上下文参数:"+$ENV);
22 |
--------------------------------------------------------------------------------
/hrun4j-cli/src/main/resources/vm/scaffold/hrun4j/cli/data/csvFile.vm:
--------------------------------------------------------------------------------
1 | parameterName
2 | 1
3 | 2
--------------------------------------------------------------------------------
/hrun4j-cli/src/main/resources/vm/scaffold/hrun4j/cli/env.vm:
--------------------------------------------------------------------------------
1 | kev=value
--------------------------------------------------------------------------------
/hrun4j-cli/src/main/resources/vm/scaffold/hrun4j/cli/gitignore.vm:
--------------------------------------------------------------------------------
1 | # Compiled class file
2 | *.class
3 |
4 | # Log file
5 | *.log
6 |
7 | # BlueJ files
8 | *.ctxt
9 |
10 | # Mobile Tools for Java (J2ME)
11 | .mtj.tmp/
12 |
13 | # Package Files #
14 | *.war
15 | *.nar
16 | *.ear
17 | *.zip
18 | *.tar.gz
19 | *.rar
20 | .env
21 |
22 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
23 | hs_err_pid*
--------------------------------------------------------------------------------
/hrun4j-cli/src/main/resources/vm/scaffold/hrun4j/cli/readMe.vm:
--------------------------------------------------------------------------------
1 | # 工程案例
2 |
3 | >本工程由hrun4j脚手架工具生成,该工程以CLI方式集成hrun4j能力
4 |
5 | ## 工程目录
6 |
7 | 使用方法参考:http://lematech.vip
--------------------------------------------------------------------------------
/hrun4j-cli/src/main/resources/vm/scaffold/hrun4j/cli/testcases/get/getScene.vm:
--------------------------------------------------------------------------------
1 | config:
2 | name: Postman Echo GET Request
3 | base_url: https://postman-echo.com
4 | variables:
5 | website: http://lematech.vip
6 | project: hrun4j
7 | author: lematechvipVar
8 | teststeps:
9 | - name: Postman Echo GET Request And Reference Api
10 | variables:
11 | author: lematech
12 | setup_hooks:
13 | - $\{BSH\('Hrun4j.bsh'\)\}
14 | request:
15 | url: /get?website=${website}&project=${project}&author=${author}&page={page}
16 | method: GET
17 | validate:
18 | - equalTo: [status_code,200]
19 | - equalTo: [body.args.website,http://lematech.vip]
20 | - equalTo: ["${author}", lematech]
21 | - equalTo: ["^website\":\"(.*?)\"$", website":"http://lematech.vip"]
22 | extract:
23 | - website: body.args.website
24 | output:
25 | - variables
26 | - extract
27 | - name: Reference Api
28 | api: apis/get.yml
29 | variables:
30 | author: ${website}
31 | validate:
32 | - equalTo: [status_code,200]
--------------------------------------------------------------------------------
/hrun4j-cli/src/main/resources/vm/scaffold/hrun4j/cli/testcases/post/postScene.vm:
--------------------------------------------------------------------------------
1 | config:
2 | name: Postman Echo postFormData And postRawText Request
3 | base_url: https://postman-echo.com
4 | teststeps:
5 | - name: Reference postFormData Api
6 | api: apis/postFormData.yml
7 | variables:
8 | website: http://lematech.vip
9 | project: hrun4j
10 | author: lematech
11 | validate:
12 | - equalTo: [status_code,200]
13 | - name: Reference postRawText Api
14 | api: apis/postRawText.yml
15 | variables:
16 | data: "This is expected to be sent back as part of response body."
17 | validate:
18 | - equalTo: [status_code,200]
--------------------------------------------------------------------------------
/hrun4j-cli/src/main/resources/vm/scaffold/hrun4j/cli/testsuite/testsuite.vm:
--------------------------------------------------------------------------------
1 | config:
2 | name: 测试用例集配置
3 | base_url: https://api.apiopen.top
4 | parameters:
5 | varA: "$\{P\(data/csvFile.csv\)\}"
6 | testcases:
7 | - name: Postman Echo GET Request
8 | testcase: testcases/get/getScene.yml
9 | - name: Postman Echo postFormData And postRawText Request
10 | testcase: testcases/post/postScene.yml
--------------------------------------------------------------------------------
/hrun4j-cli/src/main/resources/vm/scaffold/hrun4j/pom/meta-info/env.vm:
--------------------------------------------------------------------------------
1 | kev=value
--------------------------------------------------------------------------------
/hrun4j-cli/src/main/resources/vm/scaffold/hrun4j/pom/meta-info/gitignore.vm:
--------------------------------------------------------------------------------
1 | # Compiled class file
2 | *.class
3 |
4 | # Log file
5 | *.log
6 |
7 | # BlueJ files
8 | *.ctxt
9 |
10 | # Mobile Tools for Java (J2ME)
11 | .mtj.tmp/
12 |
13 | # Package Files #
14 | *.war
15 | *.nar
16 | *.ear
17 | *.zip
18 | *.tar.gz
19 | *.rar
20 | .env
21 |
22 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
23 | hs_err_pid*
--------------------------------------------------------------------------------
/hrun4j-cli/src/main/resources/vm/scaffold/hrun4j/pom/meta-info/readMe.vm:
--------------------------------------------------------------------------------
1 | # 工程案例
2 |
3 | >本工程由hrun4j脚手架工具生成,该工程以POM方式集成hrun4j能力
4 |
5 | ## 工程目录
6 |
7 | ```
8 | ├── README.md 案例说明
9 | ├── firstProject.iml
10 | ├── pom.xml POM案例
11 | └── src
12 | ├── main
13 | │ └── java
14 | │ └── io
15 | │ └── lematech
16 | │ └── firstproject
17 | │ └── testcases
18 | │ ├── Hrun4j.java --工程关键,继承Hrun4j类即可引入框架,另外配置、动态表达式引入可在此处完成
19 | │ └── functions -- 自定义方法集合
20 | │ └── MyFunction.java -- 方法实现
21 | └── test
22 | ├── java
23 | │ └── io
24 | │ └── lematech
25 | │ └── firstproject
26 | │ └── testcases
27 | │ ├── get
28 | │ │ └── GetTest.java -- 单测用例,一个目录下只需一个,目录名称要喝resources/testcases/get对应
29 | │ └── post
30 | │ └── PostTest.java -- 单测用例,一个目录下只需一个,目录名称要喝resources/testcases/post对应
31 | └── resources
32 | ├── apis -- 接口定义
33 | │ ├── get.yml
34 | │ └── post.yml
35 | ├── data -- 数据文件
36 | ├── testcases --用例文件
37 | │ ├── get
38 | │ │ └── getScene.yml
39 | │ └── post
40 | │ └── postScene.yml
41 | └── testsuite --用例集文件夹
42 | ├── testsuite.xml -- 用例集
43 | └── testsuite_all.xml -- 用例集
44 |
45 | ```
46 |
47 | ## 参数化构建
48 |
49 | 构建命令:`mvn clean test -DxmlFileName=src/test/resources/testsuite/testsuite.xml`
50 |
51 | ```xml
52 |
53 | org.apache.maven.plugins
54 | maven-surefire-plugin
55 | 2.17
56 |
57 |
58 | ${xmlFileName}
59 |
60 |
61 |
62 | ```
63 | 其中:
64 | 1. xmlFileName代表pom.xml配置的suiteXmlFile值
65 | 2. `src/test/resources/testsuite/testsuite.xml`当前工程下测试用例集相对或绝对路径
66 |
--------------------------------------------------------------------------------
/hrun4j-cli/src/main/resources/vm/scaffold/hrun4j/pom/resources/Hrun4j.vm:
--------------------------------------------------------------------------------
1 | #!/bin/java bsh.Interpreter
2 | print("Hrun4j.bsh文件所在路径即为项目工程路径");
3 | print("你好,欢迎使用Hrun4j!");
4 | print("官网:http://www.lematech.vip");
5 | print("微信公众号:lematech");
6 | print("技术交流微信:wytest");
--------------------------------------------------------------------------------
/hrun4j-cli/src/main/resources/vm/scaffold/hrun4j/pom/resources/apis/get.vm:
--------------------------------------------------------------------------------
1 | name: Postman Echo GET Request
2 | base_url: https://postman-echo.com
3 | variables:
4 | website: http://lematech.vip_api
5 | project: hrun4j_api
6 | author: lematech_api
7 | request:
8 | url: /get?website=${website}&project=${project}&author=${author}
9 | method: GET
--------------------------------------------------------------------------------
/hrun4j-cli/src/main/resources/vm/scaffold/hrun4j/pom/resources/apis/postFormData.vm:
--------------------------------------------------------------------------------
1 | name: Postman Echo POST Raw Text Request
2 | base_url: http://lematech.vip
3 | variables:
4 | website: http://lematech.vip_api
5 | project: hrun4j_api
6 | author: lematech_api
7 | request:
8 | url: /post
9 | method: POST
10 | headers:
11 | data:
12 | website: ${website}
13 | project: ${project}
14 | author: ${author}
--------------------------------------------------------------------------------
/hrun4j-cli/src/main/resources/vm/scaffold/hrun4j/pom/resources/apis/postRawText.vm:
--------------------------------------------------------------------------------
1 | name: Postman Echo POST Raw Text Request
2 | base_url: https://postman-echo.com
3 | variables:
4 | data: "This is expected to be sent back as part of response body._api"
5 | request:
6 | url: /post
7 | method: POST
8 | data: ${data}
--------------------------------------------------------------------------------
/hrun4j-cli/src/main/resources/vm/scaffold/hrun4j/pom/resources/data/csvFile.vm:
--------------------------------------------------------------------------------
1 | parameterName
2 | 1
3 | 2
--------------------------------------------------------------------------------
/hrun4j-cli/src/main/resources/vm/scaffold/hrun4j/pom/resources/testcases/get/getScene.vm:
--------------------------------------------------------------------------------
1 | config:
2 | name: Postman Echo GET Request
3 | base_url: https://postman-echo.com
4 | variables:
5 | website: http://lematech.vip
6 | project: hrun4j
7 | author: lematechvipVar
8 | teststeps:
9 | - name: Postman Echo GET Request And Reference Api
10 | variables:
11 | author: lematech
12 | setup_hooks:
13 | - $\{BSH\('Hrun4j.bsh'\)\}
14 | - $\{shFunction\(page,count,type\)\}
15 | request:
16 | url: /get?website=${website}&project=${project}&author=${author}&page={page}
17 | method: GET
18 | extract:
19 | - website: body.args.website
20 | output:
21 | - variables
22 | - extract
23 | teardown_hooks:
24 | - $\{tdFunction\("This is a joke!"\)\}
25 | validate:
26 | - equalTo: [status_code,200]
27 | - equalTo: [body.args.website,http://lematech.vip]
28 | - equalTo: ["${author}", lematech]
29 | - equalTo: ["^website\":\"(.*?)\"$", website":"http://lematech.vip"]
30 | - name: Reference Api
31 | api: apis/get.yml
32 | variables:
33 | author: lematechvip
34 | website: ${website}
35 | validate:
36 | - equalTo: [status_code,200]
--------------------------------------------------------------------------------
/hrun4j-cli/src/main/resources/vm/scaffold/hrun4j/pom/resources/testcases/post/postScene.vm:
--------------------------------------------------------------------------------
1 | config:
2 | name: Postman Echo postFormData And postRawText Request
3 | base_url: https://postman-echo.com
4 | teststeps:
5 | - name: Reference postFormData Api
6 | api: apis/postFormData.yml
7 | variables:
8 | website: http://lematech.vip
9 | project: hrun4j
10 | author: lematech
11 | validate:
12 | - equalTo: [status_code,200]
13 | - name: Reference postRawText Api
14 | api: apis/postRawText.yml
15 | variables:
16 | data: "This is expected to be sent back as part of response body."
17 | validate:
18 | - equalTo: [status_code,200]
--------------------------------------------------------------------------------
/hrun4j-cli/src/main/resources/vm/scaffold/hrun4j/pom/template/function/Hrun4j.vm:
--------------------------------------------------------------------------------
1 | package ${application.packageName};
2 |
3 | import com.googlecode.aviator.AviatorEvaluator;
4 | import ${application.packageName}.functions.MyFunction;
5 | import vip.lematech.hrun4j.base.TestBase;
6 | import vip.lematech.hrun4j.common.Constant;
7 | import vip.lematech.hrun4j.config.RunnerConfig;
8 | import org.testng.annotations.BeforeSuite;
9 | import vip.lematech.hrun4j.helper.LogHelper;
10 |
11 | /**
12 | * Extension function
13 | * @author lematech@foxmail.com
14 | * @version 1.0.1
15 | */
16 | public class Hrun4j extends TestBase {
17 | @Override
18 | @BeforeSuite
19 | public void beforeSuite(){
20 | LogHelper.info(" Add function to static code block !");
21 | AviatorEvaluator.addFunction(new MyFunction.SetupHookFunction());
22 | AviatorEvaluator.addFunction(new MyFunction.TearDownHookFunction());
23 | /**
24 | * 包名,资源路径下查找测试用例前置,默认:vip.lematech.hrun4j
25 | */
26 | RunnerConfig.getInstance().setPkgName("${application.packageName}");
27 | /**
28 | * Test case file suffix
29 | */
30 | RunnerConfig.getInstance().setTestCaseExtName(Constant.SUPPORT_TEST_CASE_FILE_EXT_YML_NAME);
31 | }
32 | }
33 |
34 |
--------------------------------------------------------------------------------
/hrun4j-cli/src/main/resources/vm/scaffold/hrun4j/pom/template/function/functions/MyFunction.vm:
--------------------------------------------------------------------------------
1 | package ${application.packageName}.functions;
2 |
3 | import com.googlecode.aviator.runtime.function.AbstractFunction;
4 | import com.googlecode.aviator.runtime.function.FunctionUtils;
5 | import com.googlecode.aviator.runtime.type.AviatorObject;
6 | import com.googlecode.aviator.runtime.type.AviatorString;
7 | import vip.lematech.hrun4j.helper.LogHelper;
8 |
9 | import java.util.Map;
10 |
11 | /**
12 | * @author lematech@foxmail.com
13 | * @version 1.0.1
14 | */
15 |
16 | public class MyFunction {
17 |
18 | /**
19 | * Custom function, set the function name will be implemented in the call supplement function
20 | */
21 | public static class SetupHookFunction extends AbstractFunction {
22 | @Override
23 | public AviatorObject call(Map env, AviatorObject page, AviatorObject type, AviatorObject count) {
24 | LogHelper.info("正在执行:{}方法,方法参数:page={},count={},type={}",this.getName(), page,count,type);
25 | String typeValue = FunctionUtils.getStringValue(type, env);
26 | Number pageValue = FunctionUtils.getNumberValue(page, env);
27 | Number countValue = FunctionUtils.getNumberValue(count, env);
28 | String spiceString = String.format("page=%s&count=%s&page=type",pageValue,countValue,typeValue);
29 | return new AviatorString(String.valueOf(spiceString));
30 | }
31 | @Override
32 | public String getName() {
33 | return "shFunction";
34 | }
35 | }
36 |
37 | /**
38 | * Custom function, set the function name will be implemented in the call supplement function
39 | */
40 | public static class TearDownHookFunction extends AbstractFunction {
41 | @Override
42 | public AviatorObject call(Map env,AviatorObject type) {
43 | LogHelper.info("正在执行:{}方法,方法参数:{}",this.getName(),type.toString());
44 | LogHelper.info("当前请求参数详细信息:{}", env.get("$REQUEST"));
45 | LogHelper.info("当前响应参数详细信息:{}", env.get("$RESPONSE"));
46 | return new AviatorString("defineResult");
47 | }
48 | @Override
49 | public String getName() {
50 | return "tdFunction";
51 | }
52 | }
53 |
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/hrun4j-cli/src/main/resources/vm/scaffold/hrun4j/pom/template/pom.vm:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 | ${projectInfo.groupId}
6 | ${projectInfo.artifactId}
7 | ${projectInfo.version}
8 | ${projectInfo.name}
9 | hrun4j pom scaffolding
10 |
11 | UTF-8
12 |
13 |
14 |
15 |
16 | vip.lematech
17 | hrun4j-core
18 | 1.0.2
19 |
20 |
21 |
22 |
23 |
24 | ${project.basedir}/src/main/java
25 |
26 |
27 | ${project.basedir}/src/main/resources
28 |
29 |
30 |
31 |
32 | ${project.basedir}/src/test/java
33 |
34 |
35 | ${project.basedir}/src/test/resources
36 |
37 |
38 |
39 |
40 | org.apache.maven.plugins
41 | maven-surefire-plugin
42 |
43 |
44 | ${xmlFileName}
45 |
46 |
47 |
48 |
49 |
50 |
51 |
--------------------------------------------------------------------------------
/hrun4j-cli/src/main/resources/vm/scaffold/hrun4j/pom/template/testcase/get/GetTest.vm:
--------------------------------------------------------------------------------
1 | package ${application.packageName}.testcases.get;
2 |
3 | import org.testng.annotations.Test;
4 | import ${application.packageName}.Hrun4j;
5 | import vip.lematech.hrun4j.core.engine.TestCaseExecutorEngine;
6 | import vip.lematech.hrun4j.entity.testcase.TestCase;
7 |
8 |
9 | /**
10 | * @author lematech@foxmail.com
11 | * @version 1.0.1
12 | */
13 | public class GetTest extends Hrun4j {
14 | @Test(dataProvider = "dataProvider")
15 | public void getScene(TestCase testCase) {
16 | TestCaseExecutorEngine.getInstance().execute(testCase);
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/hrun4j-cli/src/main/resources/vm/scaffold/hrun4j/pom/template/testcase/post/PostTest.vm:
--------------------------------------------------------------------------------
1 | package ${application.packageName}.testcases.post;
2 |
3 | import org.testng.annotations.Test;
4 | import ${application.packageName}.Hrun4j;
5 | import vip.lematech.hrun4j.core.engine.TestCaseExecutorEngine;
6 | import vip.lematech.hrun4j.entity.testcase.TestCase;
7 |
8 |
9 | /**
10 | * @author lematech@foxmail.com
11 | * @version 1.0.1
12 | */
13 | public class PostTest extends Hrun4j {
14 | @Test(dataProvider = "dataProvider")
15 | public void postScene(TestCase testCase) {
16 | TestCaseExecutorEngine.getInstance().execute(testCase);
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/hrun4j-cli/src/main/resources/vm/scaffold/hrun4j/pom/template/testsuite/testsuite.vm:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/hrun4j-cli/src/main/resources/vm/scaffold/hrun4j/pom/template/testsuite/testsuite_all.vm:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/hrun4j-cli/src/main/resources/vm/scaffold/springboot/application.vm:
--------------------------------------------------------------------------------
1 | package ${application.packageName};
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class ${application.className} {
8 | public static void main(String[] args) {
9 | SpringApplication.run(${application.className}.class, args);
10 | }
11 | }
--------------------------------------------------------------------------------
/hrun4j-cli/src/main/resources/vm/scaffold/springboot/ignore.vm:
--------------------------------------------------------------------------------
1 | # Compiled class file
2 | *.class
3 |
4 | # Log file
5 | *.log
6 |
7 | # BlueJ files
8 | *.ctxt
9 |
10 | # Mobile Tools for Java (J2ME)
11 | .mtj.tmp/
12 |
13 | # Package Files #
14 | *.war
15 | *.nar
16 | *.ear
17 | *.zip
18 | *.tar.gz
19 | *.rar
20 | .env
21 |
22 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
23 | hs_err_pid*
--------------------------------------------------------------------------------
/hrun4j-cli/src/main/resources/vm/scaffold/springboot/package-info.vm:
--------------------------------------------------------------------------------
1 | package ${application.packageName};
--------------------------------------------------------------------------------
/hrun4j-cli/src/main/resources/vm/scaffold/springboot/pom.vm:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | org.springframework.boot
7 | spring-boot-starter-parent
8 | 2.1.6.RELEASE
9 |
10 |
11 | ${projectInfo.groupId}
12 | ${projectInfo.artifactId}
13 | ${projectInfo.version}
14 | ${projectInfo.name}
15 | ${projectInfo.description}
16 |
17 |
18 | 1.8
19 |
20 |
21 |
22 |
23 | org.springframework.boot
24 | spring-boot-starter-web
25 |
26 |
27 |
28 | org.springframework.boot
29 | spring-boot-starter-test
30 | test
31 |
32 |
33 |
34 |
35 |
36 |
37 | org.springframework.boot
38 | spring-boot-maven-plugin
39 |
40 |
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/hrun4j-cli/src/main/resources/vm/scaffold/springboot/test.vm:
--------------------------------------------------------------------------------
1 | package ${application.packageName};
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.boot.test.context.SpringBootTest;
6 | import org.springframework.test.context.junit4.SpringRunner;
7 |
8 | @RunWith(SpringRunner.class)
9 | @SpringBootTest
10 | public class ApiTest {
11 | @Test
12 | public void testApi() {
13 | }
14 | }
--------------------------------------------------------------------------------
/hrun4j-cli/src/main/resources/vm/scaffold/springboot/yml.vm:
--------------------------------------------------------------------------------
1 | server:
2 | port: 8081
--------------------------------------------------------------------------------
/hrun4j-cli/src/test/java/vip/lematech/hrun4j/parse/Postman2CaseTest.java:
--------------------------------------------------------------------------------
1 | package vip.lematech.hrun4j.parse;
2 |
3 | import org.testng.Assert;
4 | import org.testng.annotations.Test;
5 | import vip.lematech.hrun4j.cli.commands.Postman2Case;
6 |
7 | import java.io.File;
8 |
9 | /**
10 | * website https://www.lematech.vip/
11 | * @author chenfanghang
12 | * @version 1.0.1
13 | */
14 | public class Postman2CaseTest {
15 |
16 | @Test
17 | public void testPostman2Case() {
18 | Postman2Case postman2Case = new Postman2Case();
19 | File file = new File("src/test/resources/postman/postman_collection.json");
20 | String target = "src/test/resources/postman";
21 | int code = postman2Case.parse(file, target);
22 | Assert.assertEquals(code, 0);
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/hrun4j-cli/src/test/resources/postman/Writing test scripts/Postman Echo DELETE.yml:
--------------------------------------------------------------------------------
1 | config:
2 | baseUrl: https://postman-echo
3 | name: Postman Echo DELETE
4 | verify: false
5 | teststeps:
6 | - name: Postman Echo DELETE
7 | request:
8 | url: /delete
9 | method: DELETE
10 | headers:
11 | Content-Type: application/json
12 | json:
13 | method: DELETE
14 | allowRedirects: true
15 | stream: true
16 | validate:
17 | - eq:
18 | - status_code
19 | - 200
20 |
--------------------------------------------------------------------------------
/hrun4j-cli/src/test/resources/postman/Writing test scripts/Postman Echo GET.yml:
--------------------------------------------------------------------------------
1 | config:
2 | baseUrl: https://postman-echo
3 | name: Postman Echo GET
4 | verify: false
5 | teststeps:
6 | - name: Postman Echo GET
7 | request:
8 | url: /get
9 | method: GET
10 | allowRedirects: true
11 | stream: true
12 | validate:
13 | - eq:
14 | - status_code
15 | - 200
16 |
--------------------------------------------------------------------------------
/hrun4j-cli/src/test/resources/postman/Writing test scripts/Postman Echo POST.yml:
--------------------------------------------------------------------------------
1 | config:
2 | baseUrl: https://postman-echo
3 | name: Postman Echo POST
4 | verify: false
5 | teststeps:
6 | - name: Postman Echo POST
7 | request:
8 | url: /post
9 | method: POST
10 | headers:
11 | Content-Type: application/json
12 | json:
13 | method: POST
14 | allowRedirects: true
15 | stream: true
16 | validate:
17 | - eq:
18 | - status_code
19 | - 200
20 |
--------------------------------------------------------------------------------
/hrun4j-cli/src/test/resources/postman/Writing test scripts/Postman Echo PUT.yml:
--------------------------------------------------------------------------------
1 | config:
2 | baseUrl: https://postman-echo
3 | name: Postman Echo PUT
4 | verify: false
5 | teststeps:
6 | - name: Postman Echo PUT
7 | request:
8 | url: /put
9 | method: PUT
10 | headers:
11 | Content-Type: application/json
12 | json:
13 | method: PUT
14 | allowRedirects: true
15 | stream: true
16 | validate:
17 | - eq:
18 | - status_code
19 | - 200
20 |
--------------------------------------------------------------------------------
/hrun4j-cli/src/test/resources/testsutie/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lematechvip/hrun4j/d41d80059c99c9eb5f84f98f609733f088413b82/hrun4j-cli/src/test/resources/testsutie/.DS_Store
--------------------------------------------------------------------------------
/hrun4j-core/README.md:
--------------------------------------------------------------------------------
1 | # hrun4j
--------------------------------------------------------------------------------
/hrun4j-core/src/main/java/vip/lematech/hrun4j/base/TestBase.java:
--------------------------------------------------------------------------------
1 | package vip.lematech.hrun4j.base;
2 |
3 | import cn.hutool.core.io.FileUtil;
4 | import vip.lematech.hrun4j.common.DefinedException;
5 | import vip.lematech.hrun4j.core.provider.NGDataProvider;
6 | import vip.lematech.hrun4j.helper.LogHelper;
7 | import org.testng.annotations.*;
8 |
9 | import java.lang.reflect.Method;
10 |
11 | /**
12 | * Test base classes for pre -, post -, and data loading
13 | *
14 | * website https://www.lematech.vip/
15 | * @author lematech@foxmail.com
16 | * @version 1.0.1
17 | *
18 | */
19 |
20 | public class TestBase {
21 | private String testCaseName;
22 | @BeforeSuite
23 | public void beforeSuite(){
24 | LogHelper.info("[========================================]@beforeSuite()");
25 | }
26 | @BeforeMethod
27 | public void setUp() {
28 | LogHelper.info("[====================" + this.testCaseName + "====================]@START");
29 | }
30 | @AfterMethod
31 | public void tearDown() {
32 | LogHelper.info("[====================" + this.testCaseName + "====================]@END");
33 | }
34 | @AfterSuite
35 | public void afterSuite(){
36 | LogHelper.info("[========================================]@afterSuite()");
37 | }
38 | @DataProvider
39 | public Object[][] dataProvider(Method method) {
40 | Object[][] objects;
41 | this.testCaseName = method.getName();
42 | String packageName = FileUtil.mainName(method.getDeclaringClass().getName());
43 | try {
44 | objects = new NGDataProvider().dataProvider(packageName, testCaseName);
45 | } catch (DefinedException e) {
46 | throw e;
47 | } catch (Exception e) {
48 | String exceptionMsg = String.format("Abnormal testng data loading occurs, and the reason for the exception is as follows: %s", e.getMessage());
49 | throw new DefinedException(exceptionMsg);
50 | }
51 | return objects;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/hrun4j-core/src/main/java/vip/lematech/hrun4j/common/DefinedException.java:
--------------------------------------------------------------------------------
1 | package vip.lematech.hrun4j.common;
2 |
3 |
4 | import vip.lematech.hrun4j.helper.LogHelper;
5 |
6 | /**
7 | * throw defined exception
8 | * website https://www.lematech.vip/
9 | * @author lematech@foxmail.com
10 | * @version 1.0.1
11 | */
12 |
13 |
14 | public class DefinedException extends RuntimeException {
15 | /**
16 | * define exception
17 | *
18 | * @param msg exception message
19 | */
20 | public DefinedException(String msg) {
21 | LogHelper.error(msg);
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/hrun4j-core/src/main/java/vip/lematech/hrun4j/config/Env.java:
--------------------------------------------------------------------------------
1 | package vip.lematech.hrun4j.config;
2 |
3 | import cn.hutool.core.io.FileUtil;
4 | import vip.lematech.hrun4j.helper.FilesHelper;
5 | import vip.lematech.hrun4j.helper.LogHelper;
6 | import vip.lematech.hrun4j.common.Constant;
7 |
8 | import java.io.File;
9 | import java.io.FileInputStream;
10 | import java.io.IOException;
11 | import java.net.URL;
12 | import java.util.HashMap;
13 | import java.util.Map;
14 | import java.util.Objects;
15 | import java.util.Properties;
16 |
17 |
18 | /**
19 | * website https://www.lematech.vip/
20 | * @author lematech@foxmail.com
21 | * @version 1.0.1
22 | */
23 | public class Env {
24 | public static Map getEnvMap() {
25 | if (envMap == null) {
26 | initializeEnv();
27 | }
28 | return envMap;
29 | }
30 |
31 | private static Map envMap;
32 |
33 | private static synchronized void initializeEnv() {
34 | if (envMap == null) {
35 | RunnerConfig.RunMode runMode = RunnerConfig.getInstance().getRunMode();
36 | envMap = new HashMap<>();
37 | envMap.putAll(System.getenv());
38 | Properties properties = new Properties();
39 | try {
40 | String envFilePath = (runMode == RunnerConfig.RunMode.POM) ? Constant.ENV_FILE_NAME : RunnerConfig.getInstance().getDotEnvPath();
41 | File searchFile = null;
42 | if (runMode == RunnerConfig.RunMode.CLI) {
43 | if(Objects.isNull(envFilePath)){
44 | return ;
45 | }
46 | if (FileUtil.isAbsolutePath(envFilePath)) {
47 | searchFile = new File(envFilePath);
48 | } else {
49 | searchFile = new File(RunnerConfig.getInstance().getWorkDirectory()
50 | , FilesHelper.filePathDecode(envFilePath));
51 | }
52 | } else if (runMode == RunnerConfig.RunMode.POM) {
53 | URL url = Thread.currentThread().getContextClassLoader().getResource(envFilePath);
54 | searchFile = new File(FilesHelper.filePathDecode(url.getPath()));
55 | }
56 | if(!searchFile.isDirectory()&&FileUtil.exist(searchFile)){
57 | properties.load(new FileInputStream(searchFile));
58 | envMap.putAll((Map) properties);
59 | }else{
60 | String exceptionMsg = Constant.ENV_FILE_NAME + " is not exist";
61 | LogHelper.warn(exceptionMsg);
62 | }
63 | } catch (Exception e) {
64 | e.printStackTrace();
65 | LogHelper.error("An error occurred loading the.env file");
66 | }
67 | }
68 |
69 | }
70 |
71 |
72 | public static void setEnv(String key, Object value) {
73 | if (envMap == null) {
74 | initializeEnv();
75 | }
76 | envMap.put(key, value);
77 | }
78 |
79 | public static Object getEnv(String key) {
80 | Object value = null;
81 | if (envMap == null) {
82 | initializeEnv();
83 | }
84 | if (envMap.containsKey(key)) {
85 | value = envMap.get(key);
86 | }
87 | return value;
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/hrun4j-core/src/main/java/vip/lematech/hrun4j/config/NamespaceMap.java:
--------------------------------------------------------------------------------
1 | package vip.lematech.hrun4j.config;
2 |
3 | import vip.lematech.hrun4j.entity.testcase.TestCase;
4 |
5 | import java.util.HashMap;
6 | import java.util.Map;
7 |
8 | /**
9 | * website https://www.lematech.vip/
10 | * @author lematech@foxmail.com
11 | * @version 1.0.1
12 | */
13 | public class NamespaceMap {
14 | public static Map getNamespaceMap() {
15 | if (namespaceMap == null) {
16 | initializeEnv();
17 | }
18 | return namespaceMap;
19 | }
20 |
21 | private static Map namespaceMap;
22 |
23 | private static synchronized void initializeEnv() {
24 | if (namespaceMap == null) {
25 | namespaceMap = new HashMap<>();
26 | }
27 | }
28 |
29 | public static void setDataObject(String key, TestCase value) {
30 | if (namespaceMap == null) {
31 | initializeEnv();
32 | }
33 | namespaceMap.put(key, value);
34 | }
35 |
36 | public static TestCase getDataObject(String key) {
37 | TestCase value = null;
38 | if (namespaceMap == null) {
39 | initializeEnv();
40 | }
41 | if (namespaceMap.containsKey(key)) {
42 | value = namespaceMap.get(key);
43 | }
44 | return value;
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/hrun4j-core/src/main/java/vip/lematech/hrun4j/config/RunnerConfig.java:
--------------------------------------------------------------------------------
1 | package vip.lematech.hrun4j.config;
2 |
3 | import cn.hutool.core.util.StrUtil;
4 | import vip.lematech.hrun4j.helper.JavaIdentifierHelper;
5 | import vip.lematech.hrun4j.common.Constant;
6 | import vip.lematech.hrun4j.common.DefinedException;
7 | import lombok.Data;
8 |
9 | import java.io.File;
10 | import java.util.*;
11 |
12 | /**
13 | * Initialize the run configuration parameters
14 | *
15 | * website https://www.lematech.vip/
16 | * @author lematech@foxmail.com
17 | * @version 1.0.1
18 | */
19 |
20 | @Data
21 | public class RunnerConfig {
22 |
23 | /**
24 | * internationalization support,support en/zh
25 | */
26 | private String i18n;
27 |
28 | public String getDotEnvPath() {
29 | return dotEnvPath;
30 | }
31 |
32 | public void setDotEnvPath(String dotEnvPath) {
33 | this.dotEnvPath = dotEnvPath;
34 | }
35 |
36 | /**
37 | * .env file path
38 | */
39 | private String dotEnvPath;
40 |
41 |
42 | /**
43 | * supports cli 、api integration
44 | */
45 | private RunMode runMode = RunMode.POM;
46 |
47 | public File getWorkDirectory() {
48 | return Objects.isNull(this.workDirectory) ? new File(Constant.DOT_PATH) : this.workDirectory;
49 | }
50 |
51 | /**
52 | * work directory
53 | */
54 | private File workDirectory;
55 |
56 | public String getPkgName() {
57 | return StrUtil.isEmpty(this.pkgName) ? Constant.SELF_ROOT_PKG_NAME : this.pkgName;
58 | }
59 |
60 | /**
61 | * package name
62 | */
63 | private String pkgName;
64 | /**
65 | * testcase extension name
66 | */
67 | private String testCaseExtName;
68 | /**
69 | * test case paths
70 | */
71 | private List testCasePaths;
72 |
73 | private static RunnerConfig instance = new RunnerConfig();
74 |
75 | /**
76 | * set package name
77 | * @param pkgName package name
78 | */
79 | public void setPkgName(String pkgName) {
80 | if (!JavaIdentifierHelper.isValidJavaFullClassName(pkgName)) {
81 | String exceptionMsg = String.format("The package name %s is invalid", pkgName);
82 | throw new DefinedException(exceptionMsg);
83 | }
84 | this.pkgName = pkgName;
85 | }
86 |
87 | private RunnerConfig() {
88 | testCasePaths = new ArrayList<>();
89 | testCaseExtName = Constant.SUPPORT_TEST_CASE_FILE_EXT_YML_NAME;
90 | }
91 |
92 | public static RunnerConfig getInstance() {
93 | return instance;
94 | }
95 |
96 | /**
97 | * supports cli 、api integration
98 | *
99 | * @author lematech@foxmail.com
100 | * @version 1.0.1
101 | */
102 | public enum RunMode {
103 | CLI, POM, PLATFORM
104 | }
105 | }
106 |
--------------------------------------------------------------------------------
/hrun4j-core/src/main/java/vip/lematech/hrun4j/config/i18n/I18NFactory.java:
--------------------------------------------------------------------------------
1 | package vip.lematech.hrun4j.config.i18n;
2 |
3 | import vip.lematech.hrun4j.common.Constant;
4 | import vip.lematech.hrun4j.config.RunnerConfig;
5 |
6 | import java.util.Locale;
7 | import java.util.ResourceBundle;
8 |
9 | /**
10 | *
11 | * website https://www.lematech.vip/
12 | * @author lematech@foxmail.com
13 | * @version 1.0.1
14 | */
15 | public class I18NFactory {
16 | private synchronized static ResourceBundle getBundle(String locale) {
17 | Locale localeLang;
18 | if (Constant.I18N_US.equalsIgnoreCase(locale)) {
19 | localeLang = new Locale("en", "US");
20 | } else if (Constant.I18N_CN.equalsIgnoreCase(locale)) {
21 | localeLang = new Locale("zh", "CN");
22 | } else {
23 | localeLang = new Locale("zh", "CN");
24 | }
25 | return ResourceBundle.getBundle("locales.message", localeLang);
26 | }
27 | public synchronized static String getLocaleMessage(String key) {
28 | return getBundle(RunnerConfig.getInstance().getI18n()).getString(key);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/hrun4j-core/src/main/java/vip/lematech/hrun4j/core/engine/TemplateEngine.java:
--------------------------------------------------------------------------------
1 | package vip.lematech.hrun4j.core.engine;
2 |
3 | import vip.lematech.hrun4j.common.DefinedException;
4 | import org.apache.velocity.Template;
5 | import org.apache.velocity.VelocityContext;
6 | import org.apache.velocity.app.VelocityEngine;
7 | import org.apache.velocity.runtime.RuntimeConstants;
8 | import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader;
9 |
10 | import java.io.StringWriter;
11 |
12 |
13 | /**
14 | * website https://www.lematech.vip/
15 | * @author lematech@foxmail.com
16 | * @version 1.0.1
17 | */
18 |
19 | public class TemplateEngine {
20 | private static VelocityEngine velocityEngine;
21 |
22 | /**
23 | * get velocity engine instance
24 | *
25 | * @return velocity engine instance
26 | */
27 | private static synchronized VelocityEngine getInstance() {
28 | if (velocityEngine == null) {
29 | velocityEngine = new VelocityEngine();
30 | velocityEngine.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
31 | velocityEngine.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());
32 | try {
33 | velocityEngine.init();
34 | } catch (Exception e) {
35 | String exceptionMsg = String.format("Velocity engine init exception :%s", e.getMessage());
36 | throw new DefinedException(exceptionMsg);
37 | }
38 | }
39 | return velocityEngine;
40 | }
41 |
42 | /**
43 | * render template by context self-defined variables
44 | * @param templateName template of name
45 | * @param context context
46 | * @return The contents of the template after rendering
47 | */
48 | public static String getTemplateRenderContent(String templateName, VelocityContext context){
49 | Template template;
50 | try {
51 | template = getInstance().getTemplate(templateName);
52 | } catch (Exception e) {
53 | String exceptionMsg = String.format("There was an exception getting the template %s,Exception Informations: ", templateName, e.getMessage());
54 | throw new DefinedException(exceptionMsg);
55 | }
56 |
57 | StringWriter sw = new StringWriter();
58 | try {
59 | template.merge(context, sw);
60 | } catch (Exception e) {
61 | String exceptionMsg = String.format("An exception occurred in the rendering engine template %s based on the constructed data,,Exception Informations: %s", templateName, e.getMessage());
62 | throw new DefinedException(exceptionMsg);
63 | }
64 | return sw.toString();
65 | }
66 |
67 |
68 | }
69 |
70 |
--------------------------------------------------------------------------------
/hrun4j-core/src/main/java/vip/lematech/hrun4j/core/engine/TestCaseExecutorEngine.java:
--------------------------------------------------------------------------------
1 | package vip.lematech.hrun4j.core.engine;
2 |
3 |
4 | import vip.lematech.hrun4j.core.runner.TestCaseRunner;
5 |
6 |
7 | /**
8 | * testcase executor engine
9 | *
10 | * website https://www.lematech.vip/
11 | * @author lematech@foxmail.com
12 | * @version 1.0.1
13 | */
14 |
15 | public class TestCaseExecutorEngine {
16 | private static TestCaseRunner tcr = null;
17 | public static synchronized TestCaseRunner getInstance() {
18 | tcr = new TestCaseRunner();
19 | return tcr;
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/hrun4j-core/src/main/java/vip/lematech/hrun4j/core/loader/TestDataLoaderFactory.java:
--------------------------------------------------------------------------------
1 | package vip.lematech.hrun4j.core.loader;
2 |
3 | import cn.hutool.core.util.StrUtil;
4 | import vip.lematech.hrun4j.common.Constant;
5 | import vip.lematech.hrun4j.common.DefinedException;
6 | import vip.lematech.hrun4j.core.loader.impl.TestDataLoaderImpl;
7 | import vip.lematech.hrun4j.core.loader.service.ITestDataLoader;
8 | import vip.lematech.hrun4j.helper.LogHelper;
9 |
10 |
11 | /**
12 | * Test data loader factory by test case extname
13 | *
14 | * website https://www.lematech.vip/
15 | * @author lematech@foxmail.com
16 | * @version 1.0.1
17 | */
18 |
19 | public class TestDataLoaderFactory {
20 | /**
21 | * get file loader
22 | * @param extName extension name
23 | * @return test data loader
24 | */
25 | public synchronized static ITestDataLoader getLoader(String extName) {
26 | if (StrUtil.isEmpty(extName)) {
27 | LogHelper.debug("Set the use case load format to YML by default");
28 | return new TestDataLoaderImpl(extName);
29 | }
30 | if (extName.equalsIgnoreCase(Constant.SUPPORT_TEST_CASE_FILE_EXT_YML_NAME)
31 | || extName.equalsIgnoreCase(Constant.SUPPORT_TEST_CASE_FILE_EXT_JSON_NAME)) {
32 | return new TestDataLoaderImpl(extName);
33 | } else {
34 | String exceptionMsg = String.format("The current extension %s is not supported.", extName);
35 | throw new DefinedException(exceptionMsg);
36 | }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/hrun4j-core/src/main/java/vip/lematech/hrun4j/core/loader/service/ITestDataLoader.java:
--------------------------------------------------------------------------------
1 | package vip.lematech.hrun4j.core.loader.service;
2 |
3 |
4 | import java.io.File;
5 |
6 |
7 | /**
8 | * Data loading define class, support file loading
9 | * website https://www.lematech.vip/
10 | * @author lematech@foxmail.com
11 | * @version 1.0.1
12 | */
13 | public interface ITestDataLoader {
14 |
15 | /**
16 | * file load
17 | *
18 | * @param fileName The file name
19 | * @param clazz The specified class
20 | * @param The generic type
21 | * @return The specified object
22 | */
23 | T load(File fileName, Class clazz);
24 | }
25 |
--------------------------------------------------------------------------------
/hrun4j-core/src/main/java/vip/lematech/hrun4j/entity/base/BaseModel.java:
--------------------------------------------------------------------------------
1 | package vip.lematech.hrun4j.entity.base;
2 |
3 | import com.fasterxml.jackson.annotation.JsonProperty;
4 | import lombok.Data;
5 |
6 | /**
7 | * website https://www.lematech.vip/
8 | * @author lematech@foxmail.com
9 | * @version 1.0.1
10 | */
11 | @Data
12 | public class BaseModel {
13 |
14 | /**
15 | * array[string]:call setup hook functions, return nothing
16 | * - '${sleep(2)}'
17 | * - '${hook_print(setup)}'
18 | * - '${modify_request_json($request, android)}'
19 | * - '${alter_response($response)}'
20 | * map:call setup hook functions, return value and assign to variable(TP)
21 | * total: '${sum_two(1, 5)}'
22 | * filed_name: get_decoded_response_field($response)
23 | * array[map]:call setup hook functions, return value and assign to variable
24 | * -total: '${sum_two(1, 5)}'
25 | * total: value1
26 | * -filed_name: get_decoded_response_field($response)
27 | */
28 |
29 | @JsonProperty(value = "setup_hooks")
30 | private T setupHooks;
31 |
32 | /**
33 | * array[string]:call teardown hook hook functions, return nothing
34 | * - '${sleep(2)}'
35 | * - '${hook_print(setup)}'
36 | * - '${modify_request_json($request, android)}'
37 | * - '${alter_response($response)}'
38 | * map:call setup hook functions, return value and assign to variable(TP)
39 | * total: '${sum_two(1, 5)}'
40 | * filed_name: get_decoded_response_field($response)
41 | * array[map]:call teardown hook functions, return value and assign to variable
42 | * -total: '${sum_two(1, 5)}'
43 | * total: value1
44 | * -filed_name: get_decoded_response_field($response)
45 | */
46 | @JsonProperty(value = "teardown_hooks")
47 | private T teardownHooks;
48 |
49 | /**
50 | * array[string]:if exp and execute exp, return value and assign to variable
51 | * $prepared_variables
52 | * map:assign to variable(TP)
53 | * var1: value1
54 | * var2: value2
55 | * array[map]:assign to variable
56 | * -var1: value1
57 | * var11: value11
58 | * -var2: value2
59 | * var21: value21
60 | */
61 | @JsonProperty(value = "variables")
62 | private T variables;
63 | }
64 |
65 |
--------------------------------------------------------------------------------
/hrun4j-core/src/main/java/vip/lematech/hrun4j/entity/http/RequestEntity.java:
--------------------------------------------------------------------------------
1 | package vip.lematech.hrun4j.entity.http;
2 |
3 |
4 | import lombok.AllArgsConstructor;
5 | import lombok.Builder;
6 | import lombok.NoArgsConstructor;
7 | import com.alibaba.fastjson.annotation.JSONField;
8 | import lombok.Data;
9 | import java.util.Map;
10 |
11 | /**
12 | * website https://www.lematech.vip/
13 | * @author lematech@foxmail.com
14 | * @version 1.0.1
15 | */
16 | @Data
17 | @Builder
18 | @NoArgsConstructor
19 | @AllArgsConstructor
20 | public class RequestEntity {
21 | @JSONField(ordinal = 2)
22 | private String method;
23 | @JSONField(ordinal = 1)
24 | private String url;
25 | /**
26 | * 1、query string for request url
27 | */
28 | @JSONField(ordinal = 4)
29 | private Map params;
30 | /**
31 | * 1、request body in json format
32 | * 2、request body in application/x-www-form-urlencoded format
33 | * 3、request body prepared with function, or reference a variable
34 | */
35 | @JSONField(ordinal = 6)
36 | private T data;
37 |
38 | /**
39 | * 1、request body in json format
40 | * 2、request body prepared with function, or reference a variable
41 | */
42 | @JSONField(ordinal = 5)
43 | private T json;
44 |
45 | @JSONField(ordinal = 3)
46 | private Map headers;
47 |
48 | @JSONField(ordinal = 8)
49 | private Integer connectTimeout;
50 |
51 | /**
52 | * Enable/disable GET/OPTIONS/POST/PUT/PATCH/DELETE/HEAD redirection. Defaults to True
53 | */
54 | @JSONField(ordinal = 11)
55 | private Boolean allowRedirects = true;
56 | @JSONField(ordinal = 9)
57 | private Integer writeTimeout;
58 |
59 | @JSONField(ordinal = 10)
60 | private Integer readTimeout;
61 |
62 |
63 | /**
64 | * request cookies
65 | */
66 | @JSONField(ordinal = 12)
67 | private Map cookies;
68 |
69 | /**
70 | * request files, used to upload files
71 | */
72 | @JSONField(ordinal = 7)
73 | private Object files;
74 | /**
75 | *
76 | */
77 | @JSONField(ordinal = 13)
78 | private Object auth;
79 | /**
80 | * Dictionary mapping protocol to the URL of the proxy
81 | */
82 | @JSONField(ordinal = 14)
83 | private Map proxy;
84 |
85 | /**
86 | * if False, the response content will be immediately downloaded.
87 | */
88 | @JSONField(ordinal = 15)
89 | private Boolean stream = true;
90 |
91 | }
92 |
--------------------------------------------------------------------------------
/hrun4j-core/src/main/java/vip/lematech/hrun4j/entity/http/ResponseEntity.java:
--------------------------------------------------------------------------------
1 | package vip.lematech.hrun4j.entity.http;
2 |
3 | import com.alibaba.fastjson.annotation.JSONField;
4 | import lombok.Data;
5 |
6 | import java.util.Map;
7 |
8 | /**
9 | * website https://www.lematech.vip/
10 | * @author lematech@foxmail.com
11 | * @version 1.0.1
12 | */
13 | @Data
14 | public class ResponseEntity {
15 | /**
16 | * status code
17 | */
18 | @JSONField(name = "status_code")
19 | private Integer statusCode;
20 | /**
21 | * response headers
22 | */
23 | private Map headers;
24 | /**
25 | * response time
26 | */
27 | private Double time;
28 |
29 | /**
30 | * response content
31 | */
32 | @JSONField(name = "body")
33 | private Object body;
34 | /**
35 | * response cookies
36 | */
37 | private Map cookies;
38 |
39 | /**
40 | * response content length
41 | */
42 | private Long contentLength;
43 | }
44 |
--------------------------------------------------------------------------------
/hrun4j-core/src/main/java/vip/lematech/hrun4j/entity/testcase/ApiModel.java:
--------------------------------------------------------------------------------
1 | package vip.lematech.hrun4j.entity.testcase;
2 |
3 | import com.alibaba.fastjson.annotation.JSONField;
4 | import com.fasterxml.jackson.annotation.JsonProperty;
5 | import lombok.AllArgsConstructor;
6 | import lombok.Builder;
7 | import lombok.NoArgsConstructor;
8 | import vip.lematech.hrun4j.entity.http.RequestEntity;
9 | import vip.lematech.hrun4j.entity.base.BaseModel;
10 | import lombok.Data;
11 | import java.util.List;
12 | import java.util.Map;
13 |
14 | /**
15 | * website https://www.lematech.vip/
16 | *
17 | * @author lematech@foxmail.com
18 | * @version 1.0.1
19 | */
20 | @Data
21 | @Builder
22 | @NoArgsConstructor
23 | @AllArgsConstructor
24 | public class ApiModel extends BaseModel {
25 | @JsonProperty(value = "name")
26 | @JSONField(ordinal = 1)
27 | private String name;
28 | @JsonProperty(value = "base_url")
29 | @JSONField(ordinal = 2)
30 | private String baseUrl;
31 |
32 | /**
33 | * array[map]:used to validate response fields,validate_func_name: [check_value, expect_value]
34 | * - equalTo: [statusCode, "200"]
35 | * array[map]:one validator definition(TP)
36 | * - "check": "statusCode"
37 | * "comparator": "equalTo"
38 | * "expect": "200"
39 | */
40 | @JSONField(ordinal = 5)
41 | private List