Project

General

Profile

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

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

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

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

    
22
/**
23
 * @author a.kohlbecker
24
 * @date Mar 3, 2014
25
 *
26
 */
27

    
28
public class SwaggerStaticIT extends WebServiceTestBase {
29

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

    
32

    
33
    @Test
34
    public void fetchSwaggerResources(){
35

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

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

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

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

    
51
        File pwd = new File("pom.xml");
52

    
53

    
54
//        System.err.println(pwd.getAbsolutePath());
55
    }
56

    
57

    
58
    @Test
59
    public void fetchSwaggerGroups(){
60

    
61
        String swagger2Endpoint= "/v2/api-docs";
62

    
63

    
64
        String staticApiDocFolder = "./target/classes/"+ StaticSwaggerApiDoc.SWAGGER_STATIC + "/api-docs/";
65

    
66
        staticApiDocFolder.replace("/", File.separator);
67

    
68

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

    
82
        File pwd = new File("pom.xml");
83

    
84

    
85
//        System.err.println(pwd.getAbsolutePath());
86
    }
87

    
88
}
(2-2/3)