Skip to content
This repository has been archived by the owner on Dec 13, 2023. It is now read-only.

Commit

Permalink
issue-3719: Added unit testcases to verify download functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
saksham2105 committed Sep 5, 2023
1 parent 4e993d3 commit 13a689d
Showing 1 changed file with 89 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* Copyright 2023 Netflix, Inc.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package com.netflix.conductor.core.storage;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.util.Map;

import org.apache.commons.io.IOUtils;
import org.junit.Before;
import org.junit.Test;

import com.netflix.conductor.common.run.ExternalStorageLocation;

import com.fasterxml.jackson.databind.ObjectMapper;

import static com.netflix.conductor.common.utils.ExternalPayloadStorage.PayloadType;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;

public class DummyPayloadStorageTest {

private DummyPayloadStorage dummyPayloadStorage;

private static final String TEST_STORAGE_PATH = "test-storage";

private ExternalStorageLocation location;

private ObjectMapper objectMapper;

public static final String MOCK_PAYLOAD = "{\n" + "\"output\": \"TEST_OUTPUT\",\n" + "}\n";

@Before
public void setup() {
dummyPayloadStorage = new DummyPayloadStorage();
objectMapper = new ObjectMapper();
location =
dummyPayloadStorage.getLocation(any(), PayloadType.TASK_OUTPUT, TEST_STORAGE_PATH);
try {
byte[] payloadBytes = MOCK_PAYLOAD.getBytes("UTF-8");
dummyPayloadStorage.upload(
location.getPath(),
new ByteArrayInputStream(payloadBytes),
payloadBytes.length);
} catch (UnsupportedEncodingException unsupportedEncodingException) {
}
}

@Test
public void testGetLocationNotNull() {
assertNotNull(location);
}

@Test
public void testDownloadForValidPath() {
try (InputStream inputStream = dummyPayloadStorage.download(location.getPath())) {
Map<String, Object> payload =
objectMapper.readValue(
IOUtils.toString(inputStream, StandardCharsets.UTF_8), Map.class);
assertTrue(payload.containsKey("output"));
assertEquals(payload.get("output"), "TEST_OUTPUT");
} catch (Exception e) {
assertTrue(e instanceof IOException);
}
}

@Test
public void testDownloadForInvalidPath() {
InputStream inputStream = dummyPayloadStorage.download("testPath");
assertNull(inputStream);
}
}

0 comments on commit 13a689d

Please sign in to comment.