-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#6 WsdlScanner to find Wsdl for needed targetNamespace-Reading
- Loading branch information
1 parent
2e5f2e2
commit 834b791
Showing
2 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
src/main/java/de/codecentric/cxf/autodetection/WsdlScanner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
src/test/java/de/codecentric/cxf/autodetection/WsdlScannerShould.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()))); | ||
} | ||
|
||
|
||
} |