From 25e96db653b1bf32c2dbb3bd9ad1b98849ea5d97 Mon Sep 17 00:00:00 2001 From: fudax Date: Mon, 17 Feb 2020 10:39:55 +0800 Subject: [PATCH] release v2.0.1 --- pom.xml | 22 +++- .../common/BaseServiceIntegrationTest.java | 3 - .../com/pr/sepp/common/HtmlCreateTest.java | 5 +- .../com/pr/sepp/common/addin/FatherTest.java | 34 +++++ .../com/pr/sepp/common/addin/MathTest.java | 12 +- .../com/pr/sepp/common/addin/SonTest.java | 34 +++++ .../sepp/common/notify/MessageServerTest.java | 86 ++++++------- .../sepp/common/service/AlertServiceTest.java | 27 ---- .../common/service/WarningServiceTest.java | 24 ++++ .../sepp/common/websocket/WebsocketTest.java | 58 ++++----- .../sepp/utils/jenkins/JenkinsClientTest.java | 116 ------------------ ...erTest.java => WarningRuleHelperTest.java} | 21 ++-- 12 files changed, 208 insertions(+), 234 deletions(-) create mode 100644 src/test/java/com/pr/sepp/common/addin/FatherTest.java create mode 100644 src/test/java/com/pr/sepp/common/addin/SonTest.java delete mode 100644 src/test/java/com/pr/sepp/common/service/AlertServiceTest.java create mode 100644 src/test/java/com/pr/sepp/common/service/WarningServiceTest.java delete mode 100644 src/test/java/com/pr/sepp/utils/jenkins/JenkinsClientTest.java rename src/test/java/com/pr/sepp/utils/rules/{AlertRuleHelperTest.java => WarningRuleHelperTest.java} (50%) diff --git a/pom.xml b/pom.xml index 2b8718a..0dc6686 100644 --- a/pom.xml +++ b/pom.xml @@ -149,6 +149,11 @@ 4.5.8 jar + + org.gitlab + java-gitlab-api + 4.1.1 + commons-beanutils @@ -180,7 +185,7 @@ commons-fileupload commons-fileupload - 1.3.3 + 1.3.2 jar @@ -290,6 +295,21 @@ java-jwt 3.8.3 + + + + + org.sonarsource.sonarqube + sonar-plugin-api-impl + 8.0 + + + org.codehaus.sonar + sonar-ws-client + 5.1 + + + diff --git a/src/test/java/com/pr/sepp/common/BaseServiceIntegrationTest.java b/src/test/java/com/pr/sepp/common/BaseServiceIntegrationTest.java index a96de8e..317010f 100644 --- a/src/test/java/com/pr/sepp/common/BaseServiceIntegrationTest.java +++ b/src/test/java/com/pr/sepp/common/BaseServiceIntegrationTest.java @@ -1,7 +1,6 @@ package com.pr.sepp.common; import com.pr.sepp.SeppApplication; -import com.pr.sepp.notify.alert.AlertMonitorHelper; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.runner.RunWith; @@ -18,8 +17,6 @@ public abstract class BaseServiceIntegrationTest { @MockBean private JavaMailSender javaMailSender; - @MockBean - private AlertMonitorHelper alertMonitorHelper; @BeforeClass public static void beforeClass() { diff --git a/src/test/java/com/pr/sepp/common/HtmlCreateTest.java b/src/test/java/com/pr/sepp/common/HtmlCreateTest.java index 80c5946..bf125f2 100644 --- a/src/test/java/com/pr/sepp/common/HtmlCreateTest.java +++ b/src/test/java/com/pr/sepp/common/HtmlCreateTest.java @@ -6,6 +6,9 @@ import java.io.IOException; +import static junit.framework.TestCase.assertNotNull; +import static junit.framework.TestCase.assertTrue; + public class HtmlCreateTest { @@ -46,6 +49,6 @@ public void test() throws IOException { HtmlCanvas htmlCanvas = html.table(attributes.add("class", "hovertable"))._table(); htmlCanvas.style()._style(); - System.out.println(htmlCanvas.toHtml()); + assertNotNull(htmlCanvas.toHtml()); } } diff --git a/src/test/java/com/pr/sepp/common/addin/FatherTest.java b/src/test/java/com/pr/sepp/common/addin/FatherTest.java new file mode 100644 index 0000000..a8d27a4 --- /dev/null +++ b/src/test/java/com/pr/sepp/common/addin/FatherTest.java @@ -0,0 +1,34 @@ +package com.pr.sepp.common.addin; + +public class FatherTest { + private String name; + + public FatherTest() { + System.out.println("--父类的无参构造函数--"); + } + + public FatherTest(String name) { + this.name = name; + System.out.println("--父类的有参构造函数--" + this.name); + } + + static { + System.out.println("--父类的静态代码块--"); + } + { + System.out.println("--父类的非静态代码块--"); + } + + public void speak() { + System.out.println("--父类的方法--"); + } + + // 加入一个main程序后 + public static void main(String[] args) { + System.out.println("--父类主程序--"); + FatherTest father1 = new FatherTest(); + FatherTest father = new FatherTest("父亲的名字"); + father1.speak(); + father.speak(); + } +} diff --git a/src/test/java/com/pr/sepp/common/addin/MathTest.java b/src/test/java/com/pr/sepp/common/addin/MathTest.java index a4db369..af1f6d2 100644 --- a/src/test/java/com/pr/sepp/common/addin/MathTest.java +++ b/src/test/java/com/pr/sepp/common/addin/MathTest.java @@ -2,10 +2,14 @@ import org.junit.Test; +import static org.junit.Assert.assertTrue; + public class MathTest { - @Test + @Test + public void transfer(){ + float a = 1.1f; + float b = 1.8f; - public void testMath() { - System.out.println(Math.pow(64, new Float((double) 1 / 3))); - } + assertTrue((int) a == (int) b); + } } diff --git a/src/test/java/com/pr/sepp/common/addin/SonTest.java b/src/test/java/com/pr/sepp/common/addin/SonTest.java new file mode 100644 index 0000000..d305c2e --- /dev/null +++ b/src/test/java/com/pr/sepp/common/addin/SonTest.java @@ -0,0 +1,34 @@ +package com.pr.sepp.common.addin; + +public class SonTest extends FatherTest { + private String name; + static { + System.out.println("--子类的静态代码块--"); + } + { + System.out.println("--子类的非静态代码块--"); + } + + SonTest() { + System.out.println("--子类的无参构造函数--"); + } + + SonTest(String name) { + this.name = name; + System.out.println("--子类的有参构造函数--" + this.name); + } + + @Override + public void speak() { + System.out.println("--子类Override了父类的方法--"); + } + + // 然后再加入一个main函数 + public static void main(String[] args) { + System.out.println("--子类主程序--"); + FatherTest father = new FatherTest("父亲的名字"); + father.speak(); + SonTest son = new SonTest("儿子的名字"); + son.speak(); + } +} \ No newline at end of file diff --git a/src/test/java/com/pr/sepp/common/notify/MessageServerTest.java b/src/test/java/com/pr/sepp/common/notify/MessageServerTest.java index 1b58856..6303b40 100644 --- a/src/test/java/com/pr/sepp/common/notify/MessageServerTest.java +++ b/src/test/java/com/pr/sepp/common/notify/MessageServerTest.java @@ -1,11 +1,11 @@ package com.pr.sepp.common.notify; -import com.pr.sepp.notify.fetch.FetchClient; -import com.pr.sepp.common.websocket.push.MessageServer; -import com.pr.sepp.notify.model.resp.GlobalDataResp; import com.github.pagehelper.PageInfo; import com.google.common.collect.Lists; import com.google.common.collect.Maps; +import com.pr.sepp.common.websocket.push.MessageServer; +import com.pr.sepp.notify.fetch.FetchClient; +import com.pr.sepp.notify.model.GlobalDataResp; import org.junit.Before; import org.junit.Ignore; import org.junit.Test; @@ -26,51 +26,51 @@ @RunWith(MockitoJUnitRunner.Silent.class) public class MessageServerTest { - @InjectMocks - private MessageServer messageServer; - @Mock - private FetchClient fetchClient; - @Mock - private WebSocketSession session; - private Map map; + @InjectMocks + private MessageServer messageServer; + @Mock + private FetchClient fetchClient; + @Mock + private WebSocketSession session; + private Map map; - @Before - public void setUp() throws Exception { - map = Maps.newHashMap(); - map.put(MESSAGE_PAGE_NUM, 1); - map.put(MESSAGE_PAGE_SIZE, 10); - map.put(PRODUCT_ID, "9"); - when(fetchClient.notifyMessage(session, ALARM)).thenReturn(new PageInfo()); - when(fetchClient.notifyMessage(session, NOTICE)).thenReturn(new PageInfo()); - } + @Before + public void setUp() throws Exception { + map = Maps.newHashMap(); + map.put(MESSAGE_PAGE_NUM, 1); + map.put(MESSAGE_PAGE_SIZE, 10); + map.put(PRODUCT_ID, "9"); + when(fetchClient.notifyMessage(session, WARNING)).thenReturn(new PageInfo()); + when(fetchClient.notifyMessage(session, MESSAGE)).thenReturn(new PageInfo()); + } - @Test - public void responseBuilderAlarmAndNoticeTest() { - map.put(MESSAGE_TYPE, Lists.newArrayList(ALARM, NOTICE)); - when(session.getAttributes()).thenReturn(map); - GlobalDataResp globalDataResp = messageServer.responseBuilder(session); - verify(session, times(2)).getAttributes(); - assertNotNull(globalDataResp); - } + @Test + public void responseBuilderWARNINGAndMESSAGETest() { + map.put(MESSAGE_TYPE, Lists.newArrayList(WARNING, MESSAGE)); + when(session.getAttributes()).thenReturn(map); + GlobalDataResp globalDataResp = messageServer.responseBuilder(session); + verify(session, times(2)).getAttributes(); + assertNotNull(globalDataResp); + } - @Test - public void responseBuilderAlarm() { - map.put(MESSAGE_TYPE, Lists.newArrayList(ALARM)); + @Test + public void responseBuilderWARNING() { + map.put(MESSAGE_TYPE, Lists.newArrayList(WARNING)); - when(session.getAttributes()).thenReturn(map); - GlobalDataResp globalDataResp = messageServer.responseBuilder(session); - verify(session, times(2)).getAttributes(); - assertNotNull(globalDataResp); - } + when(session.getAttributes()).thenReturn(map); + GlobalDataResp globalDataResp = messageServer.responseBuilder(session); + verify(session, times(2)).getAttributes(); + assertNotNull(globalDataResp); + } - @Test - public void responseBuilderNotice() { - map.put(MESSAGE_TYPE, Lists.newArrayList(NOTICE)); + @Test + public void responseBuilderMESSAGE() { + map.put(MESSAGE_TYPE, Lists.newArrayList(MESSAGE)); - when(session.getAttributes()).thenReturn(map); - GlobalDataResp globalDataResp = messageServer.responseBuilder(session); - verify(session, times(2)).getAttributes(); - assertNotNull(globalDataResp); - } + when(session.getAttributes()).thenReturn(map); + GlobalDataResp globalDataResp = messageServer.responseBuilder(session); + verify(session, times(2)).getAttributes(); + assertNotNull(globalDataResp); + } } diff --git a/src/test/java/com/pr/sepp/common/service/AlertServiceTest.java b/src/test/java/com/pr/sepp/common/service/AlertServiceTest.java deleted file mode 100644 index 165b0c1..0000000 --- a/src/test/java/com/pr/sepp/common/service/AlertServiceTest.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.pr.sepp.common.service; - -import com.pr.sepp.common.BaseServiceIntegrationTest; -import com.pr.sepp.notify.model.Alert; -import com.pr.sepp.notify.service.AlertService; -import com.github.pagehelper.PageInfo; -import org.junit.Ignore; -import org.junit.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.jdbc.Sql; - -import static org.junit.Assert.assertNull; - -public class AlertServiceTest extends BaseServiceIntegrationTest { - - @Autowired - private AlertService alertService; - - @Test - @Ignore - @Sql(scripts = "/sql/init-alert.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD) - public void testAlertListPaging() { - PageInfo alertPageInfo = alertService.alertListPaging(9, 1, 10); - assertNull(alertPageInfo); - } - -} diff --git a/src/test/java/com/pr/sepp/common/service/WarningServiceTest.java b/src/test/java/com/pr/sepp/common/service/WarningServiceTest.java new file mode 100644 index 0000000..5e72185 --- /dev/null +++ b/src/test/java/com/pr/sepp/common/service/WarningServiceTest.java @@ -0,0 +1,24 @@ +package com.pr.sepp.common.service; + +import com.pr.sepp.common.BaseServiceIntegrationTest; +import com.pr.sepp.notify.warning.service.WarningService; +import org.junit.Ignore; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.jdbc.Sql; + +import static org.junit.Assert.assertNull; + +public class WarningServiceTest extends BaseServiceIntegrationTest { + + @Autowired + private WarningService warningService; + + @Test + @Ignore + @Sql(scripts = "/sql/init-warning.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD) + public void testWarningListPaging() { + assertNull("warningPageInfo"); + } + +} diff --git a/src/test/java/com/pr/sepp/common/websocket/WebsocketTest.java b/src/test/java/com/pr/sepp/common/websocket/WebsocketTest.java index 2b84549..68d106c 100644 --- a/src/test/java/com/pr/sepp/common/websocket/WebsocketTest.java +++ b/src/test/java/com/pr/sepp/common/websocket/WebsocketTest.java @@ -26,36 +26,36 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; +import static junit.framework.TestCase.assertTrue; + @RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) public class WebsocketTest extends BaseIntegrationTest { - final CountDownLatch latch = new CountDownLatch(1); - @LocalServerPort - private int port; - private SockJsClient sockJsClient; - - @Autowired - private MessageWebSocketHandler messageWebSocketHandler; - - - @Before - public void setup() { - List transports = new ArrayList<>(); - transports.add(new WebSocketTransport(new StandardWebSocketClient())); - transports.add(new RestTemplateXhrTransport()); - this.sockJsClient = new SockJsClient(transports); - } - - - @Test - @Ignore - public void getGreeting() throws Exception { - this.sockJsClient.doHandshake(messageWebSocketHandler, - "ws://localhost:" + port + "/sepp/myHandler"); - if (latch.await(60, TimeUnit.SECONDS)) { - } else { - } - - } - + final CountDownLatch latch = new CountDownLatch(1); + @LocalServerPort + private int port; + private SockJsClient sockJsClient; + + @Autowired + private MessageWebSocketHandler messageWebSocketHandler; + + + @Before + public void setup() { + List transports = new ArrayList<>(); + transports.add(new WebSocketTransport(new StandardWebSocketClient())); + transports.add(new RestTemplateXhrTransport()); + this.sockJsClient = new SockJsClient(transports); + } + + @Test + @Ignore + public void getGreeting() throws Exception { + this.sockJsClient.doHandshake(messageWebSocketHandler, + "ws://localhost:" + port + "/sepp/myHandler"); + assertTrue(true); + if (latch.await(60, TimeUnit.SECONDS)) { + } else { + } + } } \ No newline at end of file diff --git a/src/test/java/com/pr/sepp/utils/jenkins/JenkinsClientTest.java b/src/test/java/com/pr/sepp/utils/jenkins/JenkinsClientTest.java deleted file mode 100644 index 7e5be93..0000000 --- a/src/test/java/com/pr/sepp/utils/jenkins/JenkinsClientTest.java +++ /dev/null @@ -1,116 +0,0 @@ -package com.pr.sepp.utils.jenkins; - -import com.pr.sepp.utils.jenkins.model.PipelineStep; -import com.google.common.collect.Lists; -import com.offbytwo.jenkins.JenkinsServer; -import com.offbytwo.jenkins.client.JenkinsHttpClient; -import com.offbytwo.jenkins.client.util.EncodingUtils; -import com.offbytwo.jenkins.model.Build; -import com.offbytwo.jenkins.model.JobWithDetails; -import com.offbytwo.jenkins.model.QueueItem; -import org.apache.commons.lang3.StringUtils; -import org.dom4j.DocumentException; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; - -import java.io.IOException; -import java.net.URI; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Objects; - - -@Ignore -@RunWith(MockitoJUnitRunner.Silent.class) -public class JenkinsClientTest { - - @Mock - private JenkinsClient jenkinsClient; - - - @Test - public void jobParams() throws IOException, DocumentException { - JenkinsHttpClient client = new JenkinsHttpClient(URI.create("http://ci.purang.com"), "cctest", "11c66ae929bd59799d4038c12013fdbedf"); - JenkinsHttpClient jenkinsHttpClient = new JenkinsHttpClient(URI.create("http://ci.purang.com"), "cctest", " cctest"); -// jenkinsHttpClient.get("/job/" + EncodingUtils.encode("Sky_普兰_Test") + "/" + 1637 + "/wfapi/describe", PipelineStep.class); - JenkinsServer jenkinsServer = new JenkinsServer(client); - JenkinsServer server = new JenkinsServer(jenkinsHttpClient); - JobWithDetails bill_proxy_test = server.getJob("bill_proxy_Test"); -// JenkinsClient.MyJobWithDetails myJobWithDetails = jenkinsHttpClient.get(UrlUtils.toJobBaseUrl(null, "redeploy_demo"), JenkinsClient.MyJobWithDetails.class); - JobWithDetails job = jenkinsServer.getJob("bill_proxy_Test"); - List builds = job.getBuilds(); - for (Build build : builds) { - try { - PipelineStep subPbq_deploy_test = jenkinsHttpClient.get("/job/" + EncodingUtils.encode("SubPbq_Deploy_Test") + "/" + build.getNumber() + "/wfapi/describe", PipelineStep.class); - - } catch (Exception e) { - System.out.println("===================================================" + build.getNumber()); - e.printStackTrace(); - } - -// BuildHistory buildHistory = BuildHistory.apply(build.getNumber(), build.details(), "sepp_Deploy"); -// System.out.println(buildHistory); - } - List params = jenkinsClient.jobParams("Sky_普兰_Test"); - jenkinsServer.getJob("").getAllBuilds(); - System.out.println(params); - - } - - - @Test - public void test01() { - String s = "哈哈hhh@"; - String sss = StringUtils.replace(s, "@", "sss"); - System.out.println(sss); - } - - public void o(List list, String s) { - s.replace("1", "2"); - list.add("b"); - list = Lists.newArrayList(); - list.add("c"); - - } - - - public String inverseSentence(String in, String sep) { - if (in == null) return null; - String[] strArrays = in.split(sep); - StringBuilder sb = new StringBuilder(); - for (int i = strArrays.length - 1; i >= 0; i--) { - sb.append(strArrays[i]).append(sep); - } - return sb.toString().substring(0, sb.toString().length() - 1); - } - - @Test - public void test02() { -// BuildFile buildFile = BuildFile.builder().paramKey("sb").paramValue(null).build(); -// ArrayList buildFiles = Lists.newArrayList(buildFile); -// Map collect = buildFiles.stream().collect(Collectors.toMap(BuildFile::getParamKey, BuildFile::getParamValue)); -// System.out.println(collect); - boolean b = checkRepeatBuild(new ArrayList<>(), null, null); - System.out.println(b); - } - - private boolean checkRepeatBuild(List items, String paramKey, String paramValue) { - String param = paramKey + "=" + paramValue; - if (Objects.equals(items.size(), 0)) return false; - return items.stream().anyMatch(item -> item.getParams().contains(param)); - } - - - @Test - public void nullException() throws IOException { - JenkinsHttpClient client = new JenkinsHttpClient(URI.create("http://ci.purang.com"), "cctest", "11c66ae929bd59799d4038c12013fdbedf"); - JenkinsServer jenkinsServer = new JenkinsServer(client); - JenkinsClient jenkinsClient = new JenkinsClient(jenkinsServer, client); - jenkinsClient.startBuild("testss", new HashMap<>()); - } - -} \ No newline at end of file diff --git a/src/test/java/com/pr/sepp/utils/rules/AlertRuleHelperTest.java b/src/test/java/com/pr/sepp/utils/rules/WarningRuleHelperTest.java similarity index 50% rename from src/test/java/com/pr/sepp/utils/rules/AlertRuleHelperTest.java rename to src/test/java/com/pr/sepp/utils/rules/WarningRuleHelperTest.java index eccf4a5..727cbe2 100644 --- a/src/test/java/com/pr/sepp/utils/rules/AlertRuleHelperTest.java +++ b/src/test/java/com/pr/sepp/utils/rules/WarningRuleHelperTest.java @@ -1,20 +1,21 @@ package com.pr.sepp.utils.rules; -import com.pr.sepp.sep.defect.model.Defect; import com.googlecode.aviator.AviatorEvaluator; import com.googlecode.aviator.Expression; +import com.pr.sepp.common.calculation.helper.WarningRuleHelper; +import com.pr.sepp.sep.defect.model.Defect; import org.junit.Before; import org.junit.Test; import static org.junit.Assert.assertTrue; -public class AlertRuleHelperTest { - private AlertRuleHelper alertRuleHelper; +public class WarningRuleHelperTest { + private WarningRuleHelper warningRuleHelper; private Defect defect; @Before public void setUp() { - alertRuleHelper = new AlertRuleHelper(); + warningRuleHelper = new WarningRuleHelper(); defect = new Defect(); defect.setFixTimes(10); defect.setDefectPeriod(20); @@ -26,10 +27,10 @@ public void setUp() { @Test public void execute() { - boolean fixTimes = alertRuleHelper.execute("fix_times > 5", defect); - boolean fixTimesAndFoundMeans = alertRuleHelper.execute("found_means - fix_times > 19", defect); - boolean period = alertRuleHelper.execute("(found_means - fix_times) / defect_period == 1", defect); - boolean influence = alertRuleHelper.execute("(influence - found_means) / defect_period > 0 && (influence - found_means) / defect_period < 1", defect); + boolean fixTimes = warningRuleHelper.execute("fixTimes > 5", defect); + boolean fixTimesAndFoundMeans = warningRuleHelper.execute("math.abs(fixTimes - foundMeans) > 19", defect); + boolean period = warningRuleHelper.execute("(foundMeans - fixTimes) / defectPeriod == 1", defect); + boolean influence = warningRuleHelper.execute("(influence - foundMeans) / defectPeriod > 0 && (influence - foundMeans) / defectPeriod < 1", defect); assertTrue(fixTimes); assertTrue(fixTimesAndFoundMeans); assertTrue(period); @@ -38,8 +39,8 @@ public void execute() { @Test public void execute1() { - Expression compile = AviatorEvaluator.compile("(influence - found_means) / defect_period > 0 && (influence - found_means) / defect_period < 1"); - boolean execute = alertRuleHelper.execute(compile, defect); + Expression compile = AviatorEvaluator.compile("(influence - foundMeans) / defectPeriod > 0 && (influence - foundMeans) / defectPeriod < 1"); + boolean execute = warningRuleHelper.execute(compile, defect); assertTrue(execute); } } \ No newline at end of file