Project

General

Profile

Download (2.5 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2014 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.cdm.remote;
10

    
11
import java.io.File;
12
import java.io.IOException;
13

    
14
import org.apache.commons.io.FileUtils;
15
import org.apache.log4j.Logger;
16
import org.junit.Test;
17

    
18
import eu.etaxonomy.cdm.remote.config.SwaggerGroupsConfig;
19
import eu.etaxonomy.cdm.remote.staticSwagger.StaticSwaggerApiDoc;
20

    
21
/**
22
 * @author a.kohlbecker
23
 \* @since Mar 3, 2014
24
 *
25
 */
26

    
27
public class SwaggerStaticIT extends WebServiceTestBase {
28

    
29
    public static final Logger logger = Logger.getLogger(SwaggerStaticIT.class);
30

    
31

    
32
    @Test
33
    public void fetchSwaggerResources(){
34

    
35
        String swagger2Endpoint= "/swagger-resources";
36

    
37
        String staticResourcesFolder = "./target/classes/"+ StaticSwaggerApiDoc.SWAGGER_STATIC + "/swagger-resources";
38

    
39
        staticResourcesFolder.replace("/", File.separator);
40

    
41
        logger.info("fetching swagger-resources");
42
        String response =  httpGetJson(swagger2Endpoint, null);
43
        try {
44
            FileUtils.write(new File(staticResourcesFolder), response);
45
        } catch (IOException e) {
46
            // TODO Auto-generated catch block
47
            e.printStackTrace();
48
        }
49

    
50
//        File pwd = new File("pom.xml");
51
//        System.err.println(pwd.getAbsolutePath());
52
    }
53

    
54

    
55
    @Test
56
    public void fetchSwaggerGroups(){
57

    
58
        String swagger2Endpoint= "/v2/api-docs";
59

    
60

    
61
        String staticApiDocFolder = "./target/classes/"+ StaticSwaggerApiDoc.SWAGGER_STATIC + "/api-docs/";
62

    
63
        staticApiDocFolder.replace("/", File.separator);
64

    
65

    
66
        for(SwaggerGroupsConfig group : SwaggerGroupsConfig.values()) {
67
            logger.info(group.groupName());
68
            String response =  httpGetJson(swagger2Endpoint, "group=" + group.groupName());
69
            response = response.replaceAll(",\"host\":\"([^\"]*)", ",\"host\":\"" + StaticSwaggerApiDoc.HOST);
70
            response = response.replaceAll(",\"basePath\":\"([^\"]*)", ",\"basePath\":\"" + StaticSwaggerApiDoc.BASE_PATH);
71
            try {
72
                FileUtils.write(new File(staticApiDocFolder + group.name()), response);
73
            } catch (IOException e) {
74
                // TODO Auto-generated catch block
75
                e.printStackTrace();
76
            }
77
        }
78

    
79
//        File pwd = new File("pom.xml");
80
//        System.err.println(pwd.getAbsolutePath());
81
    }
82

    
83
}
(2-2/3)