-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Broke out test version of ExternalReference from InMemory repo in order
to have more control over Bean wiring. Had to make the stub @primary for now.
- Loading branch information
earl.nolan
committed
Dec 12, 2017
1 parent
c5c8581
commit cebba97
Showing
3 changed files
with
66 additions
and
45 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
57 changes: 57 additions & 0 deletions
57
src/main/java/com/nfl/dm/shield/dynamic/repository/StubbedExternalReferenceRepository.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,57 @@ | ||
package com.nfl.dm.shield.dynamic.repository; | ||
|
||
import com.nfl.graphql.mediator.GraphQLMediator; | ||
import graphql.language.SelectionSet; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.annotation.Primary; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
import static com.nfl.dm.shield.dynamic.domain.schema.instancefield.AbstractReferenceType.REFERENCE_ID; | ||
import static com.nfl.dm.shield.dynamic.domain.schema.instancefield.AbstractReferenceType.REFERENCE_TYPE; | ||
|
||
@SuppressWarnings("unused") | ||
@Service("stubbedExternal") | ||
@Primary | ||
public class StubbedExternalReferenceRepository implements ExternalReferenceRepository { | ||
|
||
private final GraphQLMediator mediator; | ||
|
||
private final Map<String, Map<String, Map<String, Object>>> externalInstances | ||
= new ConcurrentHashMap<>(89); | ||
|
||
@Autowired | ||
public StubbedExternalReferenceRepository(GraphQLMediator mediator) { | ||
this.mediator = mediator; | ||
} | ||
|
||
@Override | ||
public GraphQLMediator buildMediator(String authHeader) { | ||
return mediator; | ||
} | ||
|
||
@Override | ||
public Map<String, Object> findById(SelectionSet selections, Map<String, String> id, String authHeader) { | ||
|
||
String typeName = id.get(REFERENCE_TYPE); | ||
if (!externalInstances.containsKey(typeName)) { | ||
return null; | ||
} | ||
|
||
return externalInstances.get(typeName).get(id.get(REFERENCE_ID)); | ||
} | ||
|
||
public void loadExternalInstance(String typeName, String id, Map<String, Object> instance) { | ||
if (!externalInstances.containsKey(typeName)) { | ||
externalInstances.put(typeName, new HashMap<>(89)); | ||
} | ||
externalInstances.get(typeName).put(id, instance); | ||
} | ||
|
||
public void clearForExternalTesting() { | ||
externalInstances.clear(); | ||
} | ||
} |
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