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

com.hltech.pact.gen.domain.client.jaxrs.JaxRsMethodRepresentationExtractor   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 23
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A extractRequestProperties(Method) 0 5 1
A JaxRsMethodRepresentationExtractor(Collection) 0 2 1
A extractClientMethodRepresentation(Method) 0 6 1
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