Skip to content

Commit

Permalink
#6 WsdlScanner to find Wsdl for needed targetNamespace-Reading
Browse files Browse the repository at this point in the history
  • Loading branch information
jonashackt committed Jan 10, 2017
1 parent 2e5f2e2 commit 834b791
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/main/java/de/codecentric/cxf/autodetection/WsdlScanner.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package de.codecentric.cxf.autodetection;

import de.codecentric.cxf.common.BootStarterCxfException;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.util.ResourceUtils;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Arrays;
import java.util.Optional;


public class WsdlScanner {

public File findWsdl(String pathInClasspath) throws IOException {

return ResourceUtils.getFile("classpath:" + pathInClasspath);
}

public File findWsdl() throws BootStarterCxfException {

try {
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();

Resource[] wsdls = resolver.getResources("**/*.wsdl");

Optional<Resource> wsdl = Arrays.stream(wsdls).findFirst();

if(wsdl.isPresent()) {
return wsdl.get().getFile();
} else {
throw new FileNotFoundException();
}
} catch (IOException e) {
throw new BootStarterCxfException("WSDL file not Found.", e);
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package de.codecentric.cxf.autodetection;


import de.codecentric.cxf.common.BootStarterCxfException;
import org.apache.maven.shared.invoker.*;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URL;
import java.util.Arrays;
import java.util.Optional;

import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;

@RunWith(SpringRunner.class)
public class WsdlScannerShould {

@Value("classpath:wsdl/Weather1.0.wsdl")
private Resource weatherServiceWsdl;

private WsdlScanner wsdlScanner = new WsdlScanner();

@Test public void
find_Wsdl_in_classpath_with_given_path() throws IOException {

File wsdl = wsdlScanner.findWsdl("wsdl/Weather1.0.wsdl");
assertThat(wsdl.getName(), is(equalTo(weatherServiceWsdl.getFile().getName())));
}

@Test public void
find_Wsdl_in_classpath() throws IOException, BootStarterCxfException {
File wsdl = wsdlScanner.findWsdl();
assertThat(wsdl.getName(), is(equalTo(weatherServiceWsdl.getFile().getName())));
}


}

0 comments on commit 834b791

Please sign in to comment.