junit test 报错,java.lang.Exception: No tests found matching [{ExactMatcher:fDisplayName=esopCreateTest],
java.lang.Exception: No tests found matching [{ExactMatcher:fDisplayName=esopCreateTest], {ExactMatcher:fDisplayName=esopCreateTest(com.cmcc.open.ss.util.EsopSynWebServiceActionTest)], {LeadingIdentifierMatcher:fClassName=com.cmcc.open.ss.util.EsopSynWebServiceActionTest,fLeadingIdentifier=esopCreateTest]] from org.junit.internal.requests.ClassRequest@57cd6a32
at org.junit.internal.requests.FilterRequest.getRunner(FilterRequest.java:35)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createFilteredTest(JUnit4TestLoader.java:77)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:68)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:43)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:444)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
原因 ---->junit 不能用静态方法,,,static...
/* * Project: zhejiang-esop-open manager Webapp * * File Created at 2017 年 11 月 16 日 * * Copyright 2016 CMCC Corporation Limited. * All rights reserved. * * This software is the confidential and proprietary information of * ZYHY Company. ("Confidential Information"). You shall not * disclose such Confidential Information and shall use it only in * accordance with the terms of the license. */ package com.cmcc.open.ss.util;import java.io.IOException;
import java.io.StringWriter;
import java.net.MalformedURLException;
import java.util.LinkedList;
import java.util.List;import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.namespace.QName;
import javax.xml.rpc.ServiceException;import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis2.AxisFault;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.rpc.client.RPCServiceClient;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;import com.cmcc.open.base.utils.TimeUtil;
import com.cmcc.open.ss.po.FieldInfo;
import com.cmcc.open.ss.po.RecordInfo;
import com.cmcc.open.ss.po.enums.EsopStatusEnums;/**
@Type RPCClient.java
@Desc webservice 客户端调用 test
@author huamao
@date 2017 年 11 月 16 日 上午 10:22:28
@version
*/
public class EsopSynWebServiceActionTest {@Before
public void setUp() throws Exception {
}@After
public void tearDown() throws Exception {
}
public static String serviceUrl = "http://localhost:8080/open_mssportal/services/hyEsopWebService?wsdl";
public static String nameSpace = "http://web.mssportal.open.cmcc.com";
public static String method = "acceptEsop";<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">调用方式</span> <span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">static</span> Object invokeShaohua() <span style="color: rgba(0, 0, 255, 1)">throws</span><span style="color: rgba(0, 0, 0, 1)"> Exception { String endpoint </span>=<span style="color: rgba(0, 0, 0, 1)"> serviceUrl; Service service </span>= <span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> Service(); Call call </span>= <span style="color: rgba(0, 0, 255, 1)">null</span><span style="color: rgba(0, 0, 0, 1)">; </span><span style="color: rgba(0, 0, 255, 1)">try</span><span style="color: rgba(0, 0, 0, 1)"> { call </span>=<span style="color: rgba(0, 0, 0, 1)"> (Call) service.createCall(); } </span><span style="color: rgba(0, 0, 255, 1)">catch</span><span style="color: rgba(0, 0, 0, 1)"> (ServiceException e) { e.printStackTrace(); } </span><span style="color: rgba(0, 0, 255, 1)">try</span><span style="color: rgba(0, 0, 0, 1)"> { call.setTargetEndpointAddress(</span><span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> java.net.URL(endpoint)); } </span><span style="color: rgba(0, 0, 255, 1)">catch</span><span style="color: rgba(0, 0, 0, 1)"> (MalformedURLException e) { e.printStackTrace(); } call.setOperationName(</span><span style="color: rgba(0, 0, 255, 1)">new</span> QName("http://web.mssportal.open.cmcc.com", "acceptEsop"<span style="color: rgba(0, 0, 0, 1)">)); String retXml </span>= (String) call.invoke(<span style="color: rgba(0, 0, 255, 1)">new</span> Object[] { "少华 webservice success"<span style="color: rgba(0, 0, 0, 1)"> }); System.out.println(retXml); </span><span style="color: rgba(0, 0, 255, 1)">return</span><span style="color: rgba(0, 0, 0, 1)"> retXml; } </span><span style="color: rgba(0, 128, 0, 1)">/**</span><span style="color: rgba(0, 128, 0, 1)"> * * </span><span style="color: rgba(128, 128, 128, 1)">@param</span><span style="color: rgba(0, 128, 0, 1)"> serviceUrl * </span><span style="color: rgba(128, 128, 128, 1)">@param</span><span style="color: rgba(0, 128, 0, 1)"> nameSpace * </span><span style="color: rgba(128, 128, 128, 1)">@param</span><span style="color: rgba(0, 128, 0, 1)"> method * </span><span style="color: rgba(128, 128, 128, 1)">@param</span><span style="color: rgba(0, 128, 0, 1)"> params * </span><span style="color: rgba(128, 128, 128, 1)">@param</span><span style="color: rgba(0, 128, 0, 1)"> classes * </span><span style="color: rgba(128, 128, 128, 1)">@return</span><span style="color: rgba(0, 128, 0, 1)"> * </span><span style="color: rgba(128, 128, 128, 1)">@throws</span><span style="color: rgba(0, 128, 0, 1)"> AxisFault </span><span style="color: rgba(0, 128, 0, 1)">*/</span><span style="color: rgba(0, 0, 0, 1)"> @SuppressWarnings(</span>"rawtypes"<span style="color: rgba(0, 0, 0, 1)">) </span><span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">static</span><span style="color: rgba(0, 0, 0, 1)"> Object[] invoke(String serviceUrl, String nameSpace, String method, Object[] params, Class[] classes) </span><span style="color: rgba(0, 0, 255, 1)">throws</span><span style="color: rgba(0, 0, 0, 1)"> AxisFault { </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">使用RPC方式调用WebService </span> RPCServiceClient client = <span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> RPCServiceClient(); Options option </span>=<span style="color: rgba(0, 0, 0, 1)"> client.getOptions(); </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">指定调用的URL </span> EndpointReference reference = <span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> EndpointReference(serviceUrl); option.setTo(reference); </span><span style="color: rgba(0, 128, 0, 1)">/*</span><span style="color: rgba(0, 128, 0, 1)"> * 设置要调用的方法 * </span><span style="color: rgba(0, 128, 0, 1); text-decoration: underline">http://ws.apache.org/axis2</span><span style="color: rgba(0, 128, 0, 1)"> 为默认的(无package的情况)命名空间, * 如果有包名,则为 </span><span style="color: rgba(0, 128, 0, 1); text-decoration: underline">http://axis2.webservice.elgin.com</span><span style="color: rgba(0, 128, 0, 1)"> ,包名倒过来即可 * method为方法名称 * </span><span style="color: rgba(0, 128, 0, 1)">*/</span><span style="color: rgba(0, 0, 0, 1)"> QName qname </span>= <span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> QName(nameSpace, method); </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">调用远程方法,并指定方法参数以及返回值类型 </span> Object[] result =<span style="color: rgba(0, 0, 0, 1)"> client.invokeBlocking(qname, params, classes); </span><span style="color: rgba(0, 0, 255, 1)">return</span><span style="color: rgba(0, 0, 0, 1)"> result; }
@Test
public static void esopCreateTest() { //junit 测试方法呀,不能加 static 啊。所以会报错。。去掉就好了。。。
RecordInfo recordInfoMain = new RecordInfo();
List<FieldInfo> list = new LinkedList<>();
//主工单信息
FieldInfo f1 = new FieldInfo("主题", "title", "新装套餐");
FieldInfo f2 = new FieldInfo("集团编号", "customNo", "5717333262");
FieldInfo f3 = new FieldInfo("集团名称", "customName", "boss");
FieldInfo f4 = new FieldInfo("客户经理", "cManagerContact", "张业华");
FieldInfo f5 = new FieldInfo("客户经理联系电话", "cManagerContactPhone", "15268521895");
FieldInfo f6 = new FieldInfo("e55 计费号", "mobileNo", "15573265301");
FieldInfo f7 = new FieldInfo("渠道 ID", "chnlId", "");
FieldInfo f8 = new FieldInfo("集团订购编号", "orderId", "7309427400");
FieldInfo f9 = new FieldInfo("企业管理员手机号码", "contactMobile", "18867105653");
FieldInfo f10 = new FieldInfo("企业管理员姓名", "contactName", "乌云");
FieldInfo f11 = new FieldInfo("企业管理员邮箱", "contactEmail", "420492899@qq.com");
FieldInfo f12 = new FieldInfo("地市编码", "cityCode", "573");
FieldInfo f13 = new FieldInfo("县市编码", "areaCode", "573002");
FieldInfo f14 = new FieldInfo("业务需求描述", "bRequirementDesc", "测试新装");
FieldInfo f15 = new FieldInfo("开通时间", "beginDate", "2017-12-01");//新装必填
FieldInfo f16 = new FieldInfo("计费开通时间", "billingDate", "2017-12-01");//新装必填
// FieldInfo f17=new FieldInfo("注销时间", "expDate", "");//注销必填
// FieldInfo f18=new FieldInfo("操作时间", "doneDate", "");//停复机必填
list.add(f1);
list.add(f2);
list.add(f3);
list.add(f4);
list.add(f5);
list.add(f6);
list.add(f7);
list.add(f8);
list.add(f9);
list.add(f10);
list.add(f11);
list.add(f12);
list.add(f13);
list.add(f14);
list.add(f15);
list.add(f16);
recordInfoMain.setFieldInfo(list);
//子工单信息
RecordInfo recordInfoSub = new RecordInfo();
List<FieldInfo> listZ = new LinkedList<>();
FieldInfo fz1 = new FieldInfo("子工单号", "subSerialNo", "71001206670563");
FieldInfo fz2 = new FieldInfo("集团订购产品编号", "groupPrdCode", "600000471376");
FieldInfo fz3 = new FieldInfo("状态", "state", "1");
FieldInfo fz4 = new FieldInfo("产品生效时间", "prodCycleBillingDate",
TimeUtil.getCurrentDate(TimeUtil.TIME_FORMAT2_24));
FieldInfo fz5 = new FieldInfo("产品失效时间", "prodCyclebExpDate", "2099-12-28 15:32:03");
listZ.add(fz1);
listZ.add(fz2);
listZ.add(fz3);
listZ.add(fz4);
listZ.add(fz5);
recordInfoSub.setFieldInfo(listZ);</span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> 创建输出流 </span> StringWriter swMain = <span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> StringWriter(); StringWriter swSub </span>= <span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> StringWriter(); String recordInfoMainStr </span>= ""<span style="color: rgba(0, 0, 0, 1)">; String recordInfoSubStr </span>= ""<span style="color: rgba(0, 0, 0, 1)">; </span><span style="color: rgba(0, 0, 255, 1)">try</span><span style="color: rgba(0, 0, 0, 1)"> { </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> 利用jdk中自带的转换类实现 </span> JAXBContext context = JAXBContext.newInstance(RecordInfo.<span style="color: rgba(0, 0, 255, 1)">class</span><span style="color: rgba(0, 0, 0, 1)">); Marshaller marshaller </span>=<span style="color: rgba(0, 0, 0, 1)"> context.createMarshaller(); </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">设置编码</span> marshaller.setProperty(Marshaller.JAXB_ENCODING, "GBK"<span style="color: rgba(0, 0, 0, 1)">); </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">是否要带 <?xml version="1.0" encoding="GBK" standalone="yes"?></span>
marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
// 格式化 xml 输出的格式
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
// 将对象转换成输出流形式的 xml
marshaller.marshal(recordInfoMain, swMain);
recordInfoMainStr = swMain.toString();
marshaller.marshal(recordInfoSub, swSub);
recordInfoSubStr = swSub.toString();
} catch (JAXBException e) {
e.printStackTrace();
}String opDetail </span>= "<opDetail>" + recordInfoMainStr + recordInfoSubStr + "</opDetail>"<span style="color: rgba(0, 0, 0, 1)">; String sheetType </span>=<span style="color: rgba(0, 0, 0, 1)"> EsopStatusEnums.ESOP_OPERATE_CREATE.getCode(); String req </span>= "{opPerson=系统:CRM访问ESB账号, opTime=20171128153135, sheetType=" +<span style="color: rgba(0, 0, 0, 1)"> sheetType </span>+ ", callTime=20171128153135, serSupplier=ZJ_AEP, serCaller=ZJ_BBOSS, serviceType=200, opCorp=杭州移动公司, serialNo=71201711281122554051, callerPwd=, opContact=13957350339, opDepart=12,opDetail=" + opDetail + "}"<span style="color: rgba(0, 0, 0, 1)">;
// req = req.replaceAll("[\t\n\r]", "");//去除换行符
System.out.println(req);
// try {
// Object[] result = invoke(serviceUrl, nameSpace, method, new Object[] {req},
// new Class[] { String.class});
// System.out.println(result[0]);
// } catch (Exception e) {
// e.printStackTrace();
// }
}}