Skip to content

Commit

Permalink
[ACS-5648] handling NPE when T-Engines are unavailable
Browse files Browse the repository at this point in the history
  • Loading branch information
kcichonczyk committed May 8, 2024
1 parent a1c090d commit 7b249d4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicReference;

import static java.text.MessageFormat.format;
Expand All @@ -88,6 +89,7 @@
import static org.alfresco.transform.common.RequestParamMap.TARGET_MIMETYPE;
import static org.alfresco.transform.config.CoreVersionDecorator.setOrClearCoreVersion;
import static org.springframework.http.HttpStatus.BAD_REQUEST;
import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR;
import static org.springframework.http.HttpStatus.OK;
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
import static org.springframework.http.MediaType.MULTIPART_FORM_DATA_VALUE;
Expand Down Expand Up @@ -268,6 +270,9 @@ public ResponseEntity<TransformConfig> transformConfig(
{
logger.info("GET Transform Config version: " + configVersion);
TransformConfig transformConfig = ((TransformRegistry) transformRegistry).getTransformConfig();
if(Objects.isNull(transformConfig)) {
throw new TransformException(INTERNAL_SERVER_ERROR, "Transform Config unavailable.");
}
transformConfig = setOrClearCoreVersion(transformConfig, configVersion);
return new ResponseEntity<>(transformConfig, OK);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
import ch.qos.logback.core.AppenderBase;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.ImmutableMap;
import org.alfresco.transform.base.registry.TransformRegistry;
import org.codehaus.plexus.util.FileUtils;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
Expand All @@ -87,6 +88,7 @@
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.boot.test.mock.mockito.SpyBean;
import org.springframework.core.io.Resource;
import org.springframework.core.io.UrlResource;
import org.springframework.http.ResponseEntity;
Expand Down Expand Up @@ -133,6 +135,8 @@ public class TransformControllerTest
public File tempDir;
@MockBean
protected SharedFileStoreClient fakeSfsClient;
@SpyBean
private TransformRegistry transformRegistry;

static void resetProbeForTesting(TransformController transformController)
{
Expand Down Expand Up @@ -495,4 +499,13 @@ public void testInterceptOfTransformException_noTransformers() throws Exception
.andExpect(content().string(containsString("TwoCustomTransformers Error Page")))
.andExpect(content().string(containsString("No transforms for: text/plain (5 bytes) -&gt; application/pdf unknown=1")));
}

@Test
public void testUnavailableTransformConfig() throws Exception {
when(transformRegistry.getTransformConfig()).thenReturn(null);

mockMvc.perform(MockMvcRequestBuilders.get(ENDPOINT_TRANSFORM_CONFIG))
.andExpect(status().isInternalServerError())
.andExpect(content().string(containsString("Transform Config unavailable.")));
}
}

0 comments on commit 7b249d4

Please sign in to comment.