maven

반응형





eclipse 에서 maven 프로젝트를 새로 생성한다.







create a simple.. 체크해주었다





이름을 짓고 피니쉬







src/test/java 에 새 패키지를 추가했다.





이런 식으로..






거기에 Junit Test Case 를 생성한다.










그리고 maven 프로젝트의 pom.xml에 다음과 같은 내용을 추가해준다.


https://github.com/rest-assured/rest-assured/wiki/GettingStarted


위 링크로 가면 자세히 나와있다.

우선 그냥 


REST Assured

JsonPath

XmlPath

JSON Schema Validation


4가지를 추가해줬다.






4가지 추가된 모습









예제로 네이버 open api 에서 해보았다.


http://developer.naver.com/wiki/pages/SrchBook


위 링크에 들어가면 예시 URL과 함께 파라미터 값도 나와있다


1. 요청 URL (request url)#

http://openapi.naver.com/search

2. 요청 변수 (request parameter)#

2.1 기본검색#

요청 변수설명
keystring (필수)이용 등록을 통해 받은 key 스트링을 입력합니다.
targetstring (필수) : book서비스를 위해서는 무조건 지정해야 합니다.
querystring (필수)검색을 원하는 질의, UTF-8 인코딩 입니다.
displayinteger : 기본값 10, 최대 100검색결과 출력건수를 지정합니다. 최대 100 까지 가능합니다.
startinteger : 기본값 1, 최대 1000검색의 시작위치를 지정할 수 있습니다. 최대 1000 까지 가능합니다.
  • 샘플 URL ('삼국지'를 검색할 경우)

http://openapi.naver.com/search?key=c1b406b32dbbbbeee5f2a36ddc14067f&query=%EC%82%BC%EA%B5%AD%EC%A7%80&display=10&start=1&target=book



위 링크의 예제 URL로 들어가보면


http://openapi.naver.com/search?key=c1b406b32dbbbbeee5f2a36ddc14067f&query=삼국지&display=10&start=1&target=book



아래와 같은 페이지가 노출되는데

여기 xml값 중 title 내용으로 확인을 해보았다.









아래와 같이 끄적끄적 한 뒤


given().when() 이런 것들은 아직 잘 모름

예시대로 해본 것 뿐 





예시코드


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package rest.test.api.com;
 
import static org.junit.Assert.fail;
 
import org.junit.Before;
 
import static io.restassured.RestAssured.*;
import static io.restassured.matcher.RestAssuredMatchers.*;
import static org.hamcrest.Matchers.*;
import static io.restassured.module.jsv.JsonSchemaValidator.*;
 
import org.junit.Test;
 
public class APITest {
 
    public APITest() {
        baseURI = "http://openapi.naver.com";
        port = 80;
    }
 
    @Test
    public void test() {
        given().
                params( //URL 주소의 파라미터 값을 넣어줌
                "key","c1b406b32dbbbbeee5f2a36ddc14067f",
                "query","삼국지",
                "display","10",
                "start","1",
                "target""book"
                ).when().
                
                /*baseURL 을 제외한 뒷부분 주소를 get하고
                 *body에서 해당 title 내용을 가져올 위치 지정 후
                 *확인할 값을 equalTo에 넣어 확인*/
        get("/search").then().body("rss.channel.title", equalTo("Naver Open API - book ::'sample'"));
    }
 
}
 
cs



body에서 rss.channel.title 인 이유는 페이지에 보면 
rss
ㄴchannel
  ㄴtitle

이런 식으로 구성되어서 그렇다.



equalTo 는 title 을 적어주어 URL을 호출했을 때 equalTo 값과 일치하는지 확인하는 부분이다.



값이 일치한다면 아래처럼 정상적으로 테스트가 초록색으로 끝난다.










반응형
반응형

 

Eclipse 에서 maven 프로젝트를 불러온 후 이상한 에러가 발생됐다.

바로 pom.xml 에서 문제 발생

코드 내부에는 다음과 같은 부분에서 에러발생

에러메시지는 다음과 같았다

DescriptionResourcePathLocationType

Plugin execution not covered by lifecycle configuration: org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (execution: default-compile, phase: compile)pom.xml/CloudAppAutomationline 99Maven Project Build Lifecycle Mapping Problem

Plugin execution not covered by lifecycle configuration: org.apache.maven.plugins:maven-compiler-plugin:3.1:testCompile (execution: default-testCompile, phase: test-compile)pom.xml/CloudAppAutomationline 99Maven Project Build Lifecycle Mapping Problem

Plugin execution not covered by lifecycle configuration: org.apache.maven.plugins:maven-resources-plugin:2.6:resources (execution: default-resources, phase: process-resources)pom.xml/CloudAppAutomationline 8Maven Project Build Lifecycle Mapping Problem

Plugin execution not covered by lifecycle configuration: org.apache.maven.plugins:maven-resources-plugin:2.6:testResources (execution: default-testResources, phase: process-test-resources)pom.xml/CloudAppAutomationline 8Maven Project Build Lifecycle Mapping Problem

 

근데 프로젝트는 이상없이 돌아가긴 했지만 거슬리는 건 가차없이 없애버려야 한다.

구글링해서 있는데로 시도 해봤지만 fail...

pom.xml에 무슨 디펜던시, 플러그인 코드를 삽입하라고 하는데 난 되지 않았다.

왜 항상 다수의 해결책은 나에게 해당되지 않는 것인가

 혹시 몰라 첨부.. 이전에 eclipse marketplace 에서 maven intergration for eclipse 를 설치 했었습니다.

 

그래도 해결되지 않아 다음 방법을 수행..

그러다 이분의 해결책을 발견 시도해보았다.

 

http://stackoverflow.com/questions/11448298/plugin-execution-not-covered-by-lifecycle-configuration-maven-error

 

설치된 뭔가가 잘못된 것 같았다.

 

우선 help > install new software 로 진입 후 

이 주소를 붙여넣는다.

http://dist.springsource.org/release/GRECLIPSE/e4.2/

 

그럼 아래 사진처럼 뜨는데 거기서 m2e 라고 된걸 체크 후 설치 수행

 

반응형

 

 

설치 ㄱㄱ

 

 

 

 

설치 진행 중 나는 TestNG 때문에 이런 창이 떴는데 어쨌든 그냥 있는 그대로 계속 킵고잉

 

 

 

 

설치가 끝난 후 이클립스 재시작을 했더니만 아래와 같은 화면이 발생

상단 Overview 빨간 문구를 클릭하니 다음과 같은 메시지 발생

그래서 Discover new m2e connectors 를 클릭했다.

 

 

그랬더니 이런 화면이 뜬다 

난 아무것도 몰라요 그냥 피니쉬

 

 

 

그럼 이런게 뜨는데 그냥 별 탈 없이 넥스트

 

그럼 설치가 좀 걸리긴 한데 설치 완료 후 이클립스 재시작 후

프로젝트를 다시 보니 

에러가 사라졌다!!!!!!

 

 

바람직한 현상이다.

 

물론 이번 문제는 다수의 문제가 아닌 소수의 문제일 수 있으므로 100% 해결책이라 말할 수 없다..

 

어쨌든 해결됐으면 장땡

 

반응형

+ Recent posts