|
1 | 1 | /**
|
2 |
| - * Copyright 2022, Optimizely Inc. and contributors |
| 2 | + * Copyright 2022-2023, Optimizely Inc. and contributors |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
@@ -84,9 +84,34 @@ public void returnNullWhenJsonIsMalformed() {
|
84 | 84 |
|
85 | 85 | @Test
|
86 | 86 | public void returnNullAndLogCorrectErrorWhenErrorResponseIsReturned() {
|
87 |
| - String responseToParse = "{\"errors\":[{\"message\":\"Exception while fetching data (/customer) : java.lang.RuntimeException: could not resolve _fs_user_id = wrong_id\",\"locations\":[{\"line\":2,\"column\":3}],\"path\":[\"customer\"],\"extensions\":{\"classification\":\"InvalidIdentifierException\"}}],\"data\":{\"customer\":null}}"; |
| 87 | + String responseToParse = "{\"errors\":[{\"message\":\"Exception while fetching data (/customer) : java.lang.RuntimeException: could not resolve _fs_user_id = wrong_id\",\"locations\":[{\"line\":2,\"column\":3}],\"path\":[\"customer\"],\"extensions\":{\"code\":\"INVALID_IDENTIFIER_EXCEPTION\", \"classification\":\"DataFetchingException\"}}],\"data\":{\"customer\":null}}"; |
88 | 88 | List<String> parsedSegments = jsonParser.parseQualifiedSegments(responseToParse);
|
89 |
| - logbackVerifier.expectMessage(Level.ERROR, "Exception while fetching data (/customer) : java.lang.RuntimeException: could not resolve _fs_user_id = wrong_id"); |
| 89 | + logbackVerifier.expectMessage(Level.WARN, "Audience segments fetch failed (invalid identifier)"); |
90 | 90 | assertEquals(null, parsedSegments);
|
91 | 91 | }
|
| 92 | + |
| 93 | + @Test |
| 94 | + public void returnNullAndLogNoErrorWhenErrorResponseIsReturnedButCodeKeyIsNotPresent() { |
| 95 | + String responseToParse = "{\"errors\":[{\"message\":\"Exception while fetching data (/customer) : java.lang.RuntimeException: could not resolve _fs_user_id = wrong_id\",\"locations\":[{\"line\":2,\"column\":3}],\"path\":[\"customer\"],\"extensions\":{\"classification\":\"DataFetchingException\"}}],\"data\":{\"customer\":null}}"; |
| 96 | + List<String> parsedSegments = jsonParser.parseQualifiedSegments(responseToParse); |
| 97 | + logbackVerifier.expectMessage(Level.ERROR, "Audience segments fetch failed (DataFetchingException)"); |
| 98 | + assertEquals(null, parsedSegments); |
| 99 | + } |
| 100 | + |
| 101 | + @Test |
| 102 | + public void returnNullAndLogCorrectErrorWhenErrorResponseIsReturnedButCodeValueIsNotInvalidIdentifierException() { |
| 103 | + String responseToParse = "{\"errors\":[{\"message\":\"Exception while fetching data (/customer) : java.lang.RuntimeException: could not resolve _fs_user_id = wrong_id\",\"locations\":[{\"line\":2,\"column\":3}],\"path\":[\"customer\"],\"extensions\":{\"code\":\"OTHER_EXCEPTIONS\", \"classification\":\"DataFetchingException\"}}],\"data\":{\"customer\":null}}"; |
| 104 | + List<String> parsedSegments = jsonParser.parseQualifiedSegments(responseToParse); |
| 105 | + logbackVerifier.expectMessage(Level.ERROR, "Audience segments fetch failed (DataFetchingException)"); |
| 106 | + assertEquals(null, parsedSegments); |
| 107 | + } |
| 108 | + |
| 109 | + @Test |
| 110 | + public void returnNullAndLogCorrectErrorWhenErrorResponseIsReturnedButCodeValueIsNotInvalidIdentifierExceptionNullClassification() { |
| 111 | + String responseToParse = "{\"errors\":[{\"message\":\"Exception while fetching data (/customer) : java.lang.RuntimeException: could not resolve _fs_user_id = wrong_id\",\"locations\":[{\"line\":2,\"column\":3}],\"path\":[\"customer\"],\"extensions\":{\"code\":\"OTHER_EXCEPTIONS\"}}],\"data\":{\"customer\":null}}"; |
| 112 | + List<String> parsedSegments = jsonParser.parseQualifiedSegments(responseToParse); |
| 113 | + logbackVerifier.expectMessage(Level.ERROR, "Audience segments fetch failed (decode error)"); |
| 114 | + assertEquals(null, parsedSegments); |
| 115 | + } |
| 116 | + |
92 | 117 | }
|
0 commit comments