SvnJunitXmlJson
来源:互联网 发布:php explode函数 编辑:程序博客网 时间:2024/05/20 18:51
#新空气-常用技术
- SVN
- GlassFish
- AWS
- XML&JSON
- JUnit
- Spring
- Hibernate
SVN
常用功能:新建分支、同步、更新、提交、合并(可不掌握)
GlassFish
官网地址 https://glassfish.java.net/ 安装方法:下载-->解压 启动:glassfish4/bin/asadmin start-domain 停止:glassfish4/bin/asadmin stop-domain domain1 访问:http://localhost:4848 【JDK环境变量需要配置】 常规配置: Applications:项目部署 Deploy:新部署项目 Undeploy:删除项目 Enable:启动 Disable:停止 Redeploy:重新部署 Reload:重载项目 Resources JDBC 配置JNDI JDBC Connection Pools 配置数据库连接 Configurations 【~~不重要~~】 JVM General Settings 配置JVM运行参数 部署:三种方式部署 1、上传文件部署 Deploy->Packaged..->Web Application->输入项目名称->OK 2、本地文件部署 Deploy->Local Packaged..->Web Application->输入项目名称->OK 3、项目文件部署 将项目文件直接copy到 /glassfish/domains/domain1/applications, 然后重启服务即可。
AWS 用到什么查什么
中文文档支持 http://www.amazonaws.cn/documentation/
所有的AWS相关文档,都可以从这里进去找到。
AWS整合Eclipse http://www.amazonaws.cn/documentation/awstoolkiteclipse/
安装这个插件,可以轻松建立各种AWS服务的相关项目。
javaCn http://aws.amazon.com/cn/sdkforjava/
JAVA开发重要的参考文档,API按产品排序,很方便检索。
产品描述 http://www.amazonaws.cn/products/
了解产品功能及特性。
XML & JSON
XML示例
<?xml version="1.0" encoding="UTF-8"?> <error errorid="error-6"> <level>minor</level> <identify>error-6</identify> <message>fail</message> </error>
* org.dom4j maven依赖<dependency> <groupId>dom4j</groupId> <artifactId>dom4j</artifactId> <version>1.6.1</version></dependency>
1、得到Document对象的三种方式
/** * 读文件、或流 或http服务 * @return */ public Document readerXML() { Document document = null; SAXReader reader = new SAXReader(); try { //reader 可以从http服务、文件或者流中直接获得获得xml数据 document = reader.read(new File("pom.xml")); } catch (DocumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } return document; } /** * 将字符串结构的xml数据直接转换成xml结构 * @param xml * @return */ public Document transToXML(String xml) { Document document = null; try { document = DocumentHelper.parseText(xml); } catch (DocumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } return document; } /** * 创建Document * @return */ public Document createXML(){ Document document = DocumentHelper.createDocument(); document.setXMLEncoding("UTF-8"); Element root = document.addElement("magus"); root.addAttribute("name", "luxiaohu"); root.addElement("age","18"); root.addElement("high").setText("1888");; return document; }
2、常用API举例说明
PS:所有使用的元素及属性都是示例
2.1 创建
//创建一个Document对象 Document document = DocumentHelper.createDocument(); //设置XML编码格式 document.setXMLEncoding("UTF-8"); //创建跟元素 Element root = document.addElement("magus"); //给指定元素新增一个属性,并为属性赋值 root.addAttribute("name", "luxiaohu"); //在指定元素下新增子元素,并为其赋值 root.addElement("age","18"); //给指定元素赋值 root.setText("test");
2.2 遍历元素
//获取根元素 Element root = document.getRootElement(); //获取某个元素下子元素 Element identify = root.element("identify"); //获取某个元素下子元素的值 String s = identify.getText() String s=root.elementText("identify"); //遍历某个元素下所有子元素 Iterator it=root.elementIterator(); for(it.hasNext()){ Element element = (Element) it.next(); ... } //遍历某个元素下所有指定元素名的元素 List identifyes = root.elements("identify"); Iterator it = identifyes.iterator(); for ( it.hasNext()) { Element elm = (Element) it.next(); ... } //获得指定节点的指定属性 Attribute attribute=root.attribute("errorid"); //获得属性的值 String text=attribute.getText(); //遍历某节点下所有属性 Element root=document.getRootElement(); Iterator it=root.attributeIterator(); for(it.hasNext()){ Attribute attribute = (Attribute) it.next(); ... }
JSON示例
Json 只有两种数据结构:1、key-value 2、数组
{ "name": "daerduo", "value": "98", "array": ["a", "b", "c", "d" ]}
* jackson2 可以序列化及反序列化任何对象。<dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>2.5.1</version></dependency>
常用API
ObjectMapper objectMapper = new ObjectMapper();//将对象转成JSON字符串 object 可为任意对象String s = objectMapper.writeValueAsString(object)//将JSON字符串 转成指定对象Object.class可以指定具体对象类Map<String, Object> map1 = (Map<String, Object>)objectMapper.readValue(s, Object.class)
JUnit4
Maven依赖
<dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.1</version> <scope>test</scope> </dependency>
常见测试方法注解
@Before/@After 该注解的方法可以有多个,在测试方法前/后执行 @BeforeClass/@AfterClass 该注解的方法只有一个,最开始/最后 执行 @Test 该注解表明方法为测试方法 @Test(expected = XXException.class) 如果出现指定异常,则测试成功。没有出现指定异常,则测试失败。 @Test(timeout = 1000) 测试时间超过1000 ms 退出测试 @Ignore("该测试由于网络原因暂时不测") 忽略 顺序:类实例化->@BeforeClass->@Before->@Test->@After->@AfterClass
常见测试执行类注解方式
在类上注解
普通JAVA项目
@RunWith(TestClassRunner.class) //可以不写,默认为该方
Spring 项目
@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = "classpath:spring-bean.xml")
Spring WEB 项目
@RunWith(SpringJUnit4ClassRunner.class)@ContextConfiguration(locations = {"file:webRoot/WEB-INF/spring/spring-bean.xml","file:webRoot/WEB-INF/spring/servlet-context.xml"})
Spring WEB Maven 项目
@RunWith(SpringJUnit4ClassRunner.class)@ContextConfiguration(locations = {"file:src/main/webapp/WEB-INF/spring/spring-bean.xml","file:src/main/webapp/WEB-INF/spring/servlet-context.xml"})
ps: 多个spring配置需要加载有逗号隔开就行
常用的判断执行结果的方法
单元测试时,需要对结果进行预判,测试结果跟预判结果一致时,测试通过。以下是常用预判方法:首先导入包:import static org.junit.Assert.*assertEquals(expected, actual); //如果expected等于actual 测试通过assertFalse(condition);//如果condition为假,测试通过assertTrue(condition);//如果condition为真,测试通过assertNotNull(object);//如果object不为null,测试通过assertNull(object);//如果object为null测试通过上面这些方法每一个都会有一个有message参数的重载方法,这个message是测试不通过时的说明文字。
0 0
- SvnJunitXmlJson
- 暗通道去雾算法实现步骤
- Design Principles: Dominance, Focal Points And Hierarchy
- c#使用ffmpeg显示rtsp视频流
- 使用XCode6打开项目以后再用XCode5出现的问题fatal error: malformed or corrupted AST file: 'Unable to load module
- Ramdisk文件系统烧写
- SvnJunitXmlJson
- qt发送邮件测试
- sql server中的ISNULL()用法详解
- hdu2389 Rain on your Parade(二分匹配hopcroft-carp算法)
- Android 官方推荐 : DialogFragment 创建对话框
- 降低员工流失率,新同事辅导的三个重点
- 路由器虚拟服务器实例演示
- java笔记07—面向对象02
- 正则表达式基本语法