Search in sources :

Example 1 with UnifiedRepositoryMalformedNameException

use of org.pentaho.platform.api.repository2.unified.UnifiedRepositoryMalformedNameException in project pentaho-platform by pentaho.

the class DefaultUnifiedRepositoryContentIT method testSymbol.

private void testSymbol(char symbol, boolean isGood) {
    DataNode goodNode = new DataNode("node");
    goodNode.setProperty("property", "whatever");
    NodeRepositoryFileData goodNodeData = new NodeRepositoryFileData(goodNode);
    DataNode badNode = new DataNode("node" + symbol);
    badNode.setProperty("property", "whatever");
    NodeRepositoryFileData badNodeData = new NodeRepositoryFileData(badNode);
    DataNode goodNodeBadProp = new DataNode("node");
    goodNodeBadProp.setProperty("property" + symbol, "whatever");
    NodeRepositoryFileData goodNodeBadPropData = new NodeRepositoryFileData(goodNodeBadProp);
    final String parentFolderPath = ClientRepositoryPaths.getUserHomeFolderPath(PentahoSessionHolder.getSession().getName());
    RepositoryFile parentFolder = repo.getFile(parentFolderPath);
    try {
        final String name = "folder" + symbol;
        final RepositoryFile folder = repo.createFolder(parentFolder.getId(), new RepositoryFile.Builder(name).folder(true).build(), null);
        failIfTrue(!isGood, symbol);
        assertEquals(name, folder.getName());
    } catch (UnifiedRepositoryMalformedNameException e) {
        failIfTrue(isGood, symbol);
    }
    try {
        final String name = "file" + symbol;
        final RepositoryFile file = repo.createFile(parentFolder.getId(), new RepositoryFile.Builder(name).build(), goodNodeData, null);
        failIfTrue(!isGood, symbol);
        assertEquals(name, file.getName());
    } catch (UnifiedRepositoryMalformedNameException e) {
        failIfTrue(isGood, symbol);
    }
    try {
        final RepositoryFile file = repo.getFile(parentFolder.getPath() + RepositoryFile.SEPARATOR + "file");
        if (file != null) {
            repo.deleteFile(file.getId(), null);
        }
        final RepositoryFile file1 = repo.createFile(parentFolder.getId(), new RepositoryFile.Builder("file").build(), badNodeData, null);
        failIfTrue(!isGood, symbol);
        assertEquals(badNodeData.getNode().getName(), repo.getDataForRead(file1.getId(), NodeRepositoryFileData.class).getNode().getName());
    } catch (UnifiedRepositoryMalformedNameException e) {
        failIfTrue(isGood, symbol);
    }
    try {
        final RepositoryFile file = repo.getFile(parentFolder.getPath() + RepositoryFile.SEPARATOR + "file");
        if (file != null) {
            repo.deleteFile(file.getId(), null);
        }
        final RepositoryFile file1 = repo.createFile(parentFolder.getId(), new RepositoryFile.Builder("file").build(), goodNodeBadPropData, null);
        failIfTrue(!isGood, symbol);
        assertEquals(goodNodeBadPropData.getNode().getProperties().iterator().next().getName(), repo.getDataForRead(file1.getId(), NodeRepositoryFileData.class).getNode().getProperties().iterator().next().getName());
    } catch (UnifiedRepositoryMalformedNameException e) {
        failIfTrue(isGood, symbol);
    }
}
Also used : DataNode(org.pentaho.platform.api.repository2.unified.data.node.DataNode) NodeRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) Matchers.anyString(org.mockito.Matchers.anyString) UnifiedRepositoryMalformedNameException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryMalformedNameException)

Aggregations

Matchers.anyString (org.mockito.Matchers.anyString)1 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)1 UnifiedRepositoryMalformedNameException (org.pentaho.platform.api.repository2.unified.UnifiedRepositoryMalformedNameException)1 DataNode (org.pentaho.platform.api.repository2.unified.data.node.DataNode)1 NodeRepositoryFileData (org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData)1