더북(TheBook)

이제 유닛 테스트(예제 3-16 참고)를 만들자. 이 유닛 테스트에서는 (내부적으로 GroovyBean DefinitionReader를 이용하는) GenericGroovyApplicationContext라는 새로운 클래스를 사용해서 빈의 정의를 로드한다. 이 클래스는 mydocuments.groovy 파일(예제 3-15)을 로드한다.

 예제 3-16 MyDocumentsBeanDefinitionReaderTest.java

package com.apress.isf.spring.test;

 

import static org.junit.Assert.assertEquals;

import static org.junit.Assert.assertNotNull;

import static org.junit.Assert.assertTrue;

 

import java.util.List;

 

import org.junit.Before;

import org.junit.Test;

import org.springframework.context.ApplicationContext;

import org.springframework.context.support.GenericGroovyApplicationContext;

 

import com.apress.isf.java.model.Document;

import com.apress.isf.java.model.Type;

import com.apress.isf.java.service.SearchEngine;

 

public class MyDocumentsBeanDefinitionReaderTest {

 

private ApplicationContext context;

private SearchEngine engine;

private Type webType;

 

@Before

public void setup() {

context = new GenericGroovyApplicationContext(

"META-INF/spring/mydocuments.groovy");

engine = context.getBean(SearchEngine.class);

webType = context.getBean("webType",Type.class);

}

 

@Test

public void testWithGroovyFindByType() {

List<Document> documents = engine.findByType(webType);

assertNotNull(documents);

assertTrue(documents.size() == 1);

assertEquals(webType.getName(), documents.get(0).getType().getName());

assertEquals(webType.getDesc(), documents.get(0).getType().getDesc());

assertEquals(webType.getExtension(),

documents.get(0).getType().getExtension());

}

 

@Test

public void testWithGroovyListAll() {

List<Document> documents = engine.listAll();

assertNotNull(documents);

assertTrue(documents.size() == 4);

}

 

}


신간 소식 구독하기
뉴스레터에 가입하시고 이메일로 신간 소식을 받아 보세요.