Test Setup Failed
Pull Request — master (#71)
by
unknown
02:21
created

JaxRsMethodRepresentationExtractor(Collection)   A

Complexity

Conditions 1

Size

Total Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
dl 0
loc 2
rs 10
1
package com.hltech.pact.gen.domain.client.jaxrs;
2
3
import com.hltech.pact.gen.domain.client.ClientMethodRepresentationExtractor;
4
import com.hltech.pact.gen.domain.client.annotation.handlers.AnnotatedMethodHandler;
5
import com.hltech.pact.gen.domain.client.model.ClientMethodRepresentation;
6
import com.hltech.pact.gen.domain.client.model.RequestRepresentation;
7
8
import java.lang.reflect.Method;
9
import java.util.Collection;
10
11
public class JaxRsMethodRepresentationExtractor implements ClientMethodRepresentationExtractor {
12
13
    private final Collection<AnnotatedMethodHandler> annotatedMethodHandlers;
14
15
    public JaxRsMethodRepresentationExtractor(Collection<AnnotatedMethodHandler> annotatedMethodHandlers) {
16
        this.annotatedMethodHandlers = annotatedMethodHandlers;
17
    }
18
19
    //TODO work in progess - pushed due to not to block other tasks
20
    //TODO add respose extraction
21
    @Override
22
    public ClientMethodRepresentation extractClientMethodRepresentation(Method clientMethod) {
23
        return ClientMethodRepresentation.builder()
24
                .requestRepresentation(extractRequestProperties(clientMethod))
25
                .responseRepresentationList(null)
26
                .build();
27
    }
28
29
    private RequestRepresentation extractRequestProperties(Method clientMethod) {
30
        return this.annotatedMethodHandlers.stream()
31
                .filter(annotationHandler -> annotationHandler.isSupported(clientMethod))
32
                .findFirst().orElseThrow(() -> new IllegalArgumentException("Unknown HTTP method"))
33
                .handleRequest(clientMethod);
34
    }
35
}
36