public void TestAddUriStructureOkController() { ConfigJsonHandler configJsonHandler = new ConfigJsonHandler(); ISchemaConfigOperations schemaConfigOperations = new SchemaConfigMemoryOperations(configJsonHandler); SchemaController schemaController = new SchemaController(configJsonHandler, schemaConfigOperations); UriStructure newUriStructure = CreateUriStructureExample("newUriExample"); ResourcesClass newResourcesClass = CreateResourceClassExample("newUriExample", "rsp", "pipaon"); List <ResourcesClass> lista = new List <ResourcesClass>(); lista.Add(newResourcesClass); InfoUriStructure structure = new InfoUriStructure(); structure.ResourcesClass = lista; structure.UriStructure = newUriStructure; var result = schemaController.AddUriStructure(structure); if (result is BadRequestObjectResult) { Assert.True(false); } else { Assert.True(true); } }
public void TestAddUriStructureOk() { try { ConfigJsonHandler configJsonHandler = new ConfigJsonHandler(); SchemaConfigFileOperations schemaConfigFileOperations = new SchemaConfigFileOperations(configJsonHandler); CreateBackUpConfig(); UriStructureGeneral uriSchema = configJsonHandler.GetUrisConfig(); UriStructure newUriStructure = CreateUriStructureExample("newUriExample"); ResourcesClass newResourcesClass = CreateResourceClassExample("newUriExample", "rsp", "pipaon"); int oldResourcesClassesCount = uriSchema.ResourcesClasses.Count; int oldUriStructuresCount = uriSchema.UriStructures.Count; configJsonHandler.AddUriStructureInfo(newUriStructure, newResourcesClass); schemaConfigFileOperations.SaveConfigJson(); ConfigJsonHandler configJsonHandler2 = new ConfigJsonHandler(); UriStructureGeneral uriSchema2 = configJsonHandler2.GetUrisConfig(); RestoreBackUpConfig(); configJsonHandler2.LoadConfigJson(); Assert.True(oldResourcesClassesCount + 1 == uriSchema2.ResourcesClasses.Count && oldUriStructuresCount + 1 == uriSchema2.UriStructures.Count); } catch (Exception) { RestoreBackUpConfig(); } }
public async void TestUriPublicationOK() { ConfigJsonHandler configJsonHandler = new ConfigJsonHandler(); var parsedJson = configJsonHandler.GetUrisConfig(); Assert.True(parsedJson != null); }
public void TestDeleteUriStructureOk() { try { ConfigJsonHandler configJsonHandler = new ConfigJsonHandler(); SchemaConfigFileOperations schemaConfigFileOperations = new SchemaConfigFileOperations(configJsonHandler); CreateBackUpConfig(); UriStructureGeneral uriSchema = configJsonHandler.GetUrisConfig(); int oldResourcesClassesCount = uriSchema.ResourcesClasses.Count; int oldUriStructuresCount = uriSchema.UriStructures.Count; if (configJsonHandler.ExistUriStructure("uriPublicationStructure")) { configJsonHandler.DeleteUriStructureInfo("uriPublicationStructure"); schemaConfigFileOperations.SaveConfigJson(); ConfigJsonHandler configJsonHandler2 = new ConfigJsonHandler(); UriStructureGeneral uriSchema2 = configJsonHandler2.GetUrisConfig(); RestoreBackUpConfig(); Assert.True(oldResourcesClassesCount == uriSchema2.ResourcesClasses.Count + 1 && oldUriStructuresCount == uriSchema2.UriStructures.Count + 1); } else { Assert.True(false); } } catch (Exception) { RestoreBackUpConfig(); } }
public void TestAddUriStructureFailUriStructureBadInfoException() { ConfigJsonHandler configJsonHandler = new ConfigJsonHandler(); UriStructure newUriStructure = CreateUriStructureExample("newUriExample"); ResourcesClass newResourcesClass = CreateResourceClassExample("newUriExample", "rsp", ""); Assert.Throws <UriStructureBadInfoException>(() => configJsonHandler.AddUriStructureInfo(newUriStructure, newResourcesClass)); }
public void TestUriPublicationFail() { Dictionary <string, string> queryString = new Dictionary <string, string>(); queryString.Add("identifier", "123d"); ConfigJsonHandler configJsonHandler = new ConfigJsonHandler(); UriFormer uriFormer = new UriFormer(configJsonHandler.GetUrisConfig()); Assert.Throws <ParametersNotConfiguredException>(() => uriFormer.GetURI("publication", queryString)); }
public bool SaveConfigFile(IFormFile formFile) { var memoryStream = new MemoryStream(); formFile.CopyTo(memoryStream); byte[] bytes = memoryStream.ToArray(); string texto = Encoding.UTF8.GetString(bytes); UriStructureGeneral uriStructureGeneral = ReaderConfigJson.Read(texto); return(ConfigJsonHandler.IsCorrectFormedUriStructure(uriStructureGeneral)); }
public void TestGetSchemaFileData() { ConfigJsonHandler configJsonHandler = new ConfigJsonHandler(); SchemaConfigFileOperations schemaConfigFileOperations = new SchemaConfigFileOperations(configJsonHandler); var bytesSchema = schemaConfigFileOperations.GetFileSchemaData(); var bytesAsString = Encoding.UTF8.GetString(bytesSchema); UriStructureGeneral uriSchema = JsonConvert.DeserializeObject <UriStructureGeneral>(bytesAsString); bool correctGenerated = uriSchema != null && uriSchema.Base != null && uriSchema.Characters != null && uriSchema.ResourcesClasses != null && uriSchema.ResourcesClasses.Count > 0 && uriSchema.UriStructures != null && uriSchema.UriStructures.Count > 0; Assert.True(correctGenerated); }
public void TestUriResearcherOK() { Dictionary <string, string> queryString = new Dictionary <string, string>(); queryString.Add("identifier", "123d"); ConfigJsonHandler configJsonHandler = new ConfigJsonHandler(); UriFormer uriFormer = new UriFormer(configJsonHandler.GetUrisConfig()); string uri = uriFormer.GetURI("AcademicDegree", queryString); string uriResultante = "http://graph.um.es/res/academic-degree/123d"; Assert.True(uriResultante.Equals(uri)); }
public void TestUriRdfTypeOK() { Dictionary <string, string> queryString = new Dictionary <string, string>(); queryString.Add("identifier", "123d"); ConfigJsonHandler configJsonHandler = new ConfigJsonHandler(); UriFormer uriFormer = new UriFormer(configJsonHandler.GetUrisConfig()); string uri = uriFormer.GetURI("http://purl.org/roh/mirror/vivo#AdvisorRole", queryString, true); string uriResultante = "http://graph.um.es/res/advisor-role/123d"; Assert.True(uriResultante.Equals(uri)); }
static void Main(string[] args) { Dictionary <string, string> queryString = new Dictionary <string, string>(); queryString.Add("identifier", "123d"); string texto = File.ReadAllText("Config/UrisConfig.json"); UriStructureGeneral uriStructure = JsonConvert.DeserializeObject <UriStructureGeneral>(texto); ConfigJsonHandler configJsonHandler = new ConfigJsonHandler(texto); UriFormer uriFormer = new UriFormer(configJsonHandler.GetUrisConfig()); string uri = uriFormer.GetURI("AdvisorRole", queryString); Console.WriteLine(uri); }
public void TestGetSchemaController() { try { ConfigJsonHandler configJsonHandler = new ConfigJsonHandler(); ISchemaConfigOperations schemaConfigOperations = new SchemaConfigMemoryOperations(configJsonHandler); SchemaController schemaController = new SchemaController(configJsonHandler, schemaConfigOperations); var result = schemaController.GetSchema(); Assert.True(true); } catch (Exception) { Assert.True(false); } }
public void TestAddUriStructureFailMatchNames() { try { ConfigJsonHandler configJsonHandler = new ConfigJsonHandler(); CreateBackUpConfig(); UriStructure newUriStructure = CreateUriStructureExample("newUriExamp"); ResourcesClass newResourcesClass = CreateResourceClassExample("newUriExample", "rsp", "pipaon"); Assert.Throws <UriStructureBadInfoException>(() => configJsonHandler.AddUriStructureInfo(newUriStructure, newResourcesClass)); } catch (Exception) { RestoreBackUpConfig(); } }
public void TestAddUriStructureFailUriStructureConfiguredException() { try { ConfigJsonHandler configJsonHandler = new ConfigJsonHandler(); CreateBackUpConfig(); UriStructure newUriStructure = CreateUriStructureExample("uriResourceStructure"); ResourcesClass newResourcesClass = CreateResourceClassExample("uriResourceStructure", "rsp", ""); Assert.Throws <UriStructureConfiguredException>(() => configJsonHandler.AddUriStructureInfo(newUriStructure, newResourcesClass)); } catch (Exception) { RestoreBackUpConfig(); } }
public void TestGetUriController() { ConfigJsonHandler configJsonHandler = new ConfigJsonHandler(); ISchemaConfigOperations schemaConfigOperations = new SchemaConfigMemoryOperations(configJsonHandler); SchemaController schemaController = new SchemaController(configJsonHandler, schemaConfigOperations); var result = schemaController.GetUriStructureInfo("uriResourceStructure"); if (result is BadRequestObjectResult) { Assert.True(false); } else { Assert.True(true); } }
public void TestDeleteUriStructureNoNameFoundError() { try { ConfigJsonHandler configJsonHandler = new ConfigJsonHandler(); SchemaConfigFileOperations schemaConfigFileOperations = new SchemaConfigFileOperations(configJsonHandler); CreateBackUpConfig(); Assert.Throws <UriStructureConfiguredException>(() => configJsonHandler.DeleteUriStructureInfo("badName")); schemaConfigFileOperations.SaveConfigJson(); configJsonHandler.GetUrisConfig(); RestoreBackUpConfig(); } catch (Exception) { RestoreBackUpConfig(); } }
public void TestAddUriStructureOk() { ConfigJsonHandler configJsonHandler = new ConfigJsonHandler(); UriStructureGeneral uriSchema = configJsonHandler.GetUrisConfig(); UriStructure newUriStructure = CreateUriStructureExample("newUriExample"); ResourcesClass newResourcesClass = CreateResourceClassExample("newUriExample", "rsp", "pipaon"); int oldResourcesClassesCount = uriSchema.ResourcesClasses.Count; int oldUriStructuresCount = uriSchema.UriStructures.Count; configJsonHandler.AddUriStructureInfo(newUriStructure, newResourcesClass); ISchemaConfigOperations schemaConfigOperations = new SchemaConfigMemoryOperations(configJsonHandler); schemaConfigOperations.SaveConfigJson(); UriStructureGeneral uriSchema2 = configJsonHandler.GetUrisConfig(); Assert.True(oldResourcesClassesCount + 1 == uriSchema2.ResourcesClasses.Count && oldUriStructuresCount + 1 == uriSchema2.UriStructures.Count); }
public void TestDeleteUriStructureOk() { ConfigJsonHandler configJsonHandler = new ConfigJsonHandler(); UriStructureGeneral uriSchema = configJsonHandler.GetUrisConfig(); int oldResourcesClassesCount = uriSchema.ResourcesClasses.Count; int oldUriStructuresCount = uriSchema.UriStructures.Count; if (configJsonHandler.ExistUriStructure("uriResourceStructure")) { configJsonHandler.DeleteUriStructureInfo("uriResourceStructure"); ISchemaConfigOperations schemaConfigOperations = new SchemaConfigMemoryOperations(configJsonHandler); schemaConfigOperations.SaveConfigJson(); UriStructureGeneral uriSchema2 = configJsonHandler.GetUrisConfig(); Assert.True(oldResourcesClassesCount > uriSchema2.ResourcesClasses.Count && oldUriStructuresCount > uriSchema2.UriStructures.Count); } else { Assert.True(false); } }
public void TestBadFormedJson() { ConfigJsonHandler configJsonHandler = new ConfigJsonHandler(); ISchemaConfigOperations schemaConfigOperations = new SchemaConfigMemoryOperations(configJsonHandler); SchemaController schemaController = new SchemaController(configJsonHandler, schemaConfigOperations); var stream = new MemoryStream(); var writer = new StreamWriter(stream); writer.Write(jsonConfigBad); writer.Flush(); stream.Position = 0; var file = new FormFile(stream, 0, stream.Length, null, "config.json"); var result = schemaController.ReplaceSchemaConfig(file); if (result is BadRequestObjectResult) { Assert.True(true); } else { Assert.True(false); } }
public SchemaConfigMemoryOperations(ConfigJsonHandler configJsonHandler) { _configJsonHandler = configJsonHandler; }
public bool SaveConfigJson() { return(ConfigJsonHandler.IsCorrectFormedUriStructure(_configJsonHandler.GetUrisConfig())); }
public FactoryController(ConfigJsonHandler configJsonHandler) { _configJsonHandler = configJsonHandler; }
public SchemaController(ConfigJsonHandler configJsonHandler, ISchemaConfigOperations schemaConfigOperations) { _configJsonHandler = configJsonHandler; _schemaConfigOperations = schemaConfigOperations; }
public AddParametersFilter(ConfigJsonHandler configJsonHandler) { _configJsonHandler = configJsonHandler; }
public static void Get() { UriStructureGeneral structureGeneral = new UriStructureGeneral() { Base = "http://graph.um.es" }; List <Characters> characters = new List <Characters>(); Characters charac = new Characters() { Character = "resource", LabelCharacter = "res" }; characters.Add(charac); structureGeneral.Characters = characters; Component baseC = new Component() { UriComponent = "base", UriComponentValue = "base", UriComponentOrder = 1, Mandatory = true, FinalCharacter = "/" }; Component character = new Component() { UriComponent = "character", UriComponentValue = "character@resource", UriComponentOrder = 2, Mandatory = true, FinalCharacter = "/" }; Component resource = new Component() { UriComponent = "resourceClass", UriComponentValue = "resourceClass", UriComponentOrder = 3, Mandatory = true, FinalCharacter = "/" }; Component identifier = new Component() { UriComponent = "identifier", UriComponentValue = "@ID", UriComponentOrder = 4, Mandatory = true, FinalCharacter = "" }; List <Component> componentes = new List <Component>(); componentes.Add(baseC); componentes.Add(character); componentes.Add(resource); componentes.Add(identifier); UriStructure uriStructure = new UriStructure() { Name = "test", Components = componentes }; structureGeneral.UriStructures = new List <UriStructure>(); structureGeneral.UriStructures.Add(uriStructure); ResourcesClass clas = new ResourcesClass() { LabelResourceClass = "project-object", ResourceClass = "Project", ResourceURI = "test" }; ResourcesClass clas2 = new ResourcesClass() { LabelResourceClass = "researcher", ResourceClass = "Researcher", ResourceURI = "test" }; structureGeneral.ResourcesClasses = new List <ResourcesClass>(); structureGeneral.ResourcesClasses.Add(clas); structureGeneral.ResourcesClasses.Add(clas2); string uriSchemaJson = JsonConvert.SerializeObject(structureGeneral); ConfigJsonHandler config = new ConfigJsonHandler(uriSchemaJson); Dictionary <string, string> queryString = new Dictionary <string, string>(); queryString.Add("identifier", "123d"); UriFormer uriFormer = new UriFormer(config.GetUrisConfig()); string uri = uriFormer.GetURI("Project", queryString); Console.WriteLine(uri); }
public IActionResult Get() { UriStructureGeneral structureGeneral = new UriStructureGeneral() { Base = "http://graph.um.es" }; List <Characters> characters = new List <Characters>(); Characters charac = new Characters() { Character = "resource", LabelCharacter = "res" }; characters.Add(charac); structureGeneral.Characters = characters; Component baseC = new Component() { UriComponent = "base", UriComponentValue = "base", UriComponentOrder = 1, Mandatory = true, FinalCharacter = "/" }; Component character = new Component() { UriComponent = "character", UriComponentValue = "character@RESOURCE", UriComponentOrder = 2, Mandatory = true, FinalCharacter = "/" }; Component resource = new Component() { UriComponent = "resourceClass", UriComponentValue = "resourceClass@RESOURCECLASS", UriComponentOrder = 3, Mandatory = true, FinalCharacter = "/" }; Component identifier = new Component() { UriComponent = "identifier", UriComponentValue = "@ID", UriComponentOrder = 4, Mandatory = true, FinalCharacter = "" }; List <Component> componentes = new List <Component>(); componentes.Add(baseC); componentes.Add(character); componentes.Add(resource); componentes.Add(identifier); UriStructure uriStructure = new UriStructure() { Name = "test", Components = componentes }; structureGeneral.UriStructures = new List <UriStructure>(); structureGeneral.UriStructures.Add(uriStructure); ResourcesClass clas = new ResourcesClass() { LabelResourceClass = "prueba", ResourceClass = "Test", ResourceURI = "test" }; structureGeneral.ResourcesClasses = new List <ResourcesClass>(); structureGeneral.ResourcesClasses.Add(clas); string uriSchemaJson = JsonConvert.SerializeObject(structureGeneral); ConfigJsonHandler config = new ConfigJsonHandler(uriSchemaJson); FactoryController factoryController = new FactoryController(config); return(factoryController.GenerateUri("Test", "1234")); }
public void TestDeleteUriStructureNoNameFoundError() { ConfigJsonHandler configJsonHandler = new ConfigJsonHandler(); Assert.Throws <UriStructureConfiguredException>(() => configJsonHandler.DeleteUriStructureInfo("badName")); }