-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'ypiel/TCOMP-2408_ComponentException_only_ExceptionCause…
…' of [email protected]:Talend/component-runtime.git into ypiel/TCOMP-2408_ComponentException_only_ExceptionCause
- Loading branch information
Showing
5 changed files
with
265 additions
and
6 deletions.
There are no files selected for viewing
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
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
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
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
132 changes: 132 additions & 0 deletions
132
...tools/src/test/java/org/talend/sdk/component/tools/validator/HttpClientValidatorTest.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,132 @@ | ||
/** | ||
* Copyright (C) 2006-2024 Talend Inc. - www.talend.com | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.talend.sdk.component.tools.validator; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.stream.Stream; | ||
|
||
import org.apache.xbean.finder.AnnotationFinder; | ||
import org.apache.xbean.finder.archive.ClassesArchive; | ||
import org.junit.jupiter.api.Test; | ||
import org.talend.sdk.component.api.service.dependency.DynamicDependencies; | ||
import org.talend.sdk.component.api.service.http.HttpClient; | ||
import org.talend.sdk.component.api.service.http.Request; | ||
|
||
class HttpClientValidatorTest { | ||
|
||
@Test | ||
void validateClassExtendWrongCLass() { | ||
final HttpValidator validator = new HttpValidator(); | ||
AnnotationFinder finder = new AnnotationFinder(new ClassesArchive(ClientKoWrongExtends.class)); | ||
final Stream<String> errors = | ||
validator.validate(finder, Arrays.asList(ClientKoWrongExtends.class)); | ||
assertEquals(1, errors.count()); | ||
} | ||
|
||
@Test | ||
void validateClassDoNotExtendHttpClient() { | ||
final HttpValidator validator = new HttpValidator(); | ||
AnnotationFinder finder = new AnnotationFinder(new ClassesArchive(ClientKoNotExtendsAnything.class)); | ||
final Stream<String> errors = | ||
validator.validate(finder, Arrays.asList(ClientKoNotExtendsAnything.class)); | ||
assertEquals(1, errors.count()); | ||
} | ||
|
||
@Test | ||
void validateClassMethodMissingRequestAnnotation() { | ||
final HttpValidator validator = new HttpValidator(); | ||
AnnotationFinder finder = new AnnotationFinder(new ClassesArchive(WrongClientMissingOneRequest.class)); | ||
final Stream<String> errors = | ||
validator.validate(finder, Arrays.asList(WrongClientMissingOneRequest.class)); | ||
assertEquals(1, errors.count()); | ||
} | ||
|
||
@Test | ||
void validateClassMethodWithOtherAnnotation() { | ||
final HttpValidator validator = new HttpValidator(); | ||
AnnotationFinder finder = new AnnotationFinder(new ClassesArchive(WrongClientUsingOneWrongAnnotation.class)); | ||
final Stream<String> errors = | ||
validator.validate(finder, Arrays.asList(WrongClientUsingOneWrongAnnotation.class)); | ||
assertEquals(1, errors.count()); | ||
} | ||
|
||
@Test | ||
void validateWrongClientNoMethodRequest() { | ||
final HttpValidator validator = new HttpValidator(); | ||
AnnotationFinder finder = new AnnotationFinder(new ClassesArchive(WrongClientNoMethodRequest.class)); | ||
final Stream<String> errors = | ||
validator.validate(finder, Arrays.asList(WrongClientNoMethodRequest.class)); | ||
assertEquals(1, errors.count()); | ||
} | ||
|
||
@Test | ||
void validateClassOK() { | ||
final HttpValidator validator = new HttpValidator(); | ||
AnnotationFinder finder = new AnnotationFinder(new ClassesArchive(ClientCorrect.class)); | ||
final Stream<String> noerrors = | ||
validator.validate(finder, Arrays.asList(ClientCorrect.class)); | ||
assertEquals(0, noerrors.count()); | ||
} | ||
|
||
interface ClientCorrect extends HttpClient { | ||
|
||
@Request(method = "POST") | ||
String main1(String ok); | ||
} | ||
|
||
interface ClientKoWrongExtends extends List { | ||
|
||
@Request | ||
List<Object> main(String payload); | ||
} | ||
|
||
interface ClientKoNotExtendsAnything { | ||
|
||
@Request | ||
String main(); | ||
} | ||
|
||
interface WrongClientMissingOneRequest extends HttpClient { | ||
|
||
// It misses @Request | ||
String queryA(String ok); | ||
|
||
@Request(method = "POST") | ||
String queryB(String ok); | ||
} | ||
|
||
interface WrongClientUsingOneWrongAnnotation extends HttpClient { | ||
|
||
// It misses @Request | ||
@DynamicDependencies | ||
String queryA(String ok); | ||
|
||
@Request(method = "POST") | ||
String queryB(String ok); | ||
} | ||
|
||
interface WrongClientNoMethodRequest extends HttpClient { | ||
|
||
// It misses @Request | ||
String queryA(String ok); | ||
|
||
// It misses @Request | ||
String queryB(String ok); | ||
} | ||
} |