Skip to content

Commit

Permalink
Unit test v1 for AzureFileNameParser class
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergio De Lorenzis committed Mar 20, 2024
1 parent 2292493 commit d889d34
Showing 1 changed file with 79 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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 org.apache.hop.vfs.azure;

import org.apache.commons.vfs2.FileSystemException;
import org.apache.commons.vfs2.FileType;
import org.apache.commons.vfs2.provider.VfsComponentContext;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.mockito.Mockito;

import java.util.Arrays;
import java.util.Collection;

import static org.junit.Assert.*;
@RunWith(Parameterized.class)
public class AzureFileNameParserTest {

private AzureFileNameParser parser;

private final String inputUri;
private final String expectedScheme;
private final String expectedContainer;
private final String expectedPathAfterContainer;

private final FileType expectedType;

@Before
public void setup(){
parser = new AzureFileNameParser();
}

public AzureFileNameParserTest(String inputUri, String expectedScheme, String expectedContainer, String expectedPathAfterContainer, FileType expectedType) {
this.inputUri = inputUri;
this.expectedScheme = expectedScheme;
this.expectedContainer = expectedContainer;
this.expectedPathAfterContainer = expectedPathAfterContainer;
this.expectedType = expectedType;
}

@Parameterized.Parameters
public static Collection azureUris() {
return Arrays.asList(new Object[][] {
{ "azfs:/hopsa/container/folder1/parquet-test-delo2-azfs-00-0001.parquet","azfs", "container","/folder1/parquet-test-delo2-azfs-00-0001.parquet", FileType.FILE },
{ "azfs:/hopsa/container/folder1/", "azfs", "container","/folder1", FileType.FOLDER },
{ "azure://test/folder1/", "azure", "test", "/folder1", FileType.FOLDER },
{ "azure://mycontainer/folder1/parquet-test-delo2-azfs-00-0001.parquet","azure", "mycontainer","/folder1/parquet-test-delo2-azfs-00-0001.parquet", FileType.FILE },
});
}

@Test
public void parseUri() throws FileSystemException {
VfsComponentContext context = Mockito.mock(VfsComponentContext.class);

AzureFileName actual = (AzureFileName) parser.parseUri(context, null, inputUri);

assertEquals(expectedScheme, actual.getScheme());
assertEquals(expectedContainer, actual.getContainer());
assertEquals(expectedPathAfterContainer, actual.getPathAfterContainer());
assertEquals(expectedType, actual.getType());
}
}

0 comments on commit d889d34

Please sign in to comment.