Example usage for org.springframework.core.io ClassPathResource ClassPathResource

List of usage examples for org.springframework.core.io ClassPathResource ClassPathResource

Introduction

In this page you can find the example usage for org.springframework.core.io ClassPathResource ClassPathResource.

Prototype

public ClassPathResource(String path) 

Source Link

Document

Create a new ClassPathResource for ClassLoader usage.

Usage

From source file:org.eclipse.hono.service.auth.impl.FileBasedAuthenticationServiceTest.java

/**
 * Loads permissions from file./*from  w  w  w  . j a v  a2s  . c om*/
 * 
 * @throws IOException if the permissions cannot be loaded.
 */
@BeforeClass
public static void loadPermissions() throws IOException {

    final AuthTokenHelper tokenFactory = mock(AuthTokenHelper.class);
    when(tokenFactory.createToken(anyString(), any(Authorities.class))).thenReturn(TOKEN);
    when(tokenFactory.getTokenLifetime()).thenReturn(TOKEN_LIFETIME);

    final AuthenticationServerConfigProperties props = new AuthenticationServerConfigProperties();
    props.setPermissionsPath(new ClassPathResource("authentication-service-test-permissions.json"));

    authService = new FileBasedAuthenticationService();
    authService.setConfig(props);
    authService.setTokenFactory(tokenFactory);
    authService.loadPermissions();
}

From source file:org.surfnet.cruncher.model.LoginDataTest.java

@Test
public void testJsonConversion() throws IOException {
    LoginData loginData = mapper.readValue(new ClassPathResource("stats.json").getInputStream(),
            LoginData.class);
    List<Integer> data = loginData.getData();
    int totalFromData = 0;
    for (Integer entryCount : data) {
        totalFromData += entryCount;//from   w ww  .  j av a2s. c o  m
    }
    assertEquals(loginData.getTotal(), totalFromData);
}

From source file:fr.univlorraine.mondossierweb.utils.RequestUtils.java

public RequestUtils() {
    try {//from  w ww . j a v  a2  s.c  o m

        File file = new ClassPathResource("apogeeRequest.xml").getFile();
        FileInputStream fileInput = new FileInputStream(file);
        properties = new Properties();
        properties.loadFromXML(fileInput);
        fileInput.close();

        //         Enumeration enuKeys = properties.keys();
        //         while (enuKeys.hasMoreElements()) {
        //            String key = (String) enuKeys.nextElement();
        //            String value = properties.getProperty(key);
        //            System.out.println(key + ": " + value);
        //         }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:CommentTest.java

@Test
public void findAllCommentTest() {
    ListableBeanFactory bf;/*from  www .  j a  va  2  s .c  o  m*/
    bf = new XmlBeanFactory(new ClassPathResource("applicationContext.xml"));
    ICommentaireDao m = (ICommentaireDao) bf.getBean("commentaireDao");
    System.out.print("Je suis ici");
    List<Commentaire> u = m.findAll();
    System.out.print("Je suis ici");

    for (Commentaire p : u) {
        System.out.println("nom=" + p.getComment_text());
    }

}

From source file:com.intelligentsia.dowsers.entity.manager.SamplePerson1Test.java

@Override
public Resource getResource() {
    return new ClassPathResource("dowsers-context-sample1.xml");
}

From source file:cherry.foundation.telno.AreaCodeTableFactoryTest.java

@Test
public void test() throws Exception {

    List<Resource> resources = new ArrayList<>(9);
    resources.add(new ClassPathResource("cherry/goods/telno/soumu/000124070.xls"));
    resources.add(new ClassPathResource("cherry/goods/telno/soumu/000124071.xls"));
    resources.add(new ClassPathResource("cherry/goods/telno/soumu/000124072.xls"));
    resources.add(new ClassPathResource("cherry/goods/telno/soumu/000124073.xls"));
    resources.add(new ClassPathResource("cherry/goods/telno/soumu/000124074.xls"));
    resources.add(new ClassPathResource("cherry/goods/telno/soumu/000124075.xls"));
    resources.add(new ClassPathResource("cherry/goods/telno/soumu/000124076.xls"));
    resources.add(new ClassPathResource("cherry/goods/telno/soumu/000124077.xls"));
    resources.add(new ClassPathResource("cherry/goods/telno/soumu/000124078.xls"));
    AreaCodeTableFactory factory = new AreaCodeTableFactory();
    factory.setSoumuExcelParser(new SoumuExcelParser());
    factory.setResources(resources);//  ww w .  j av  a2 s  . c  o m

    Trie<String, Integer> trie = factory.getObject();
    SortedMap<String, Integer> map = trie.prefixMap("042");
    assertEquals(790, map.size());
    assertEquals(new TreeSet<Integer>(asList(2, 3, 4)), new TreeSet<>(map.values()));

    assertEquals(4554 + 5683 + 3400 + 5343 + 5307 + 3000 + 5548 + 4526 + 5330, trie.size());
    assertEquals(Trie.class, factory.getObjectType());
    assertFalse(factory.isSingleton());
}

From source file:org.mule.module.facebook.FacebookConnectorGenericUnitTest.java

@Before
public void setup() throws IOException {
    connector = new FacebookConnector();
    connector.setAccessToken("ACCESS_TOKEN");
    client = mock(Client.class);
    connector.setClient(client);/*  w  w w .  j av  a2s. c o m*/
    resource = mock(WebResource.class);
    final BufferedImage image = ImageIO.read(new ClassPathResource("image.jpg").getInputStream());

    when(client.resource((URI) anyObject())).thenReturn(resource);
    when(resource.queryParam(anyString(), anyString())).thenReturn(resource);
    when(resource.queryParam("type", "user")).thenReturn(resource);
    when(resource.queryParam("type", "event")).thenReturn(resource);
    when(resource.queryParam("type", "checkin")).thenReturn(resource);
    when(resource.queryParam("type", "post")).thenReturn(resource);
    when(resource.queryParam("type", "page")).thenReturn(resource);
    when(resource.queryParam("type", "group")).thenReturn(resource);
    when(resource.get(String.class)).thenReturn(jsonResponse);
    when(resource.get(BufferedImage.class)).thenReturn(image);
    when(resource.post(String.class, eq(anyObject()))).thenReturn(jsonResponse);

}

From source file:org.terasoluna.gfw.functionaltest.app.download.ImageFileDownloadView.java

@Override
protected InputStream getInputStream(Map<String, Object> model, HttpServletRequest request) throws IOException {
    Resource resource = new ClassPathResource("image/Duke.png");
    return resource.getInputStream();
}

From source file:nl.surfnet.coin.api.client.OpenConextJsonParserTest.java

@Test
public void testParseResultWrapper() throws Exception {
    Group20Entry entry = parser//from  w w w.j ava  2 s.c  om
            .parseGroups20(new ClassPathResource("multiple-wrapped-groups20.json").getInputStream());
    assertEquals(3, entry.getEntry().size());
}