Skip to content

Commit

Permalink
Add failing test case
Browse files Browse the repository at this point in the history
  • Loading branch information
Ndiritu committed Sep 6, 2024
1 parent bc7ea68 commit 51809fa
Show file tree
Hide file tree
Showing 4 changed files with 230 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
package com.microsoft.kiota;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

import com.microsoft.kiota.serialization.AdditionalDataHolder;
import com.microsoft.kiota.serialization.Parsable;
import com.microsoft.kiota.serialization.ParseNode;
import com.microsoft.kiota.serialization.SerializationWriter;
import com.microsoft.kiota.store.BackedModel;
import com.microsoft.kiota.store.BackingStore;
import com.microsoft.kiota.store.BackingStoreFactorySingleton;

public class BaseCollectionPaginationCountResponse implements AdditionalDataHolder, BackedModel, Parsable {

/**
* Stores model information.
*/
@jakarta.annotation.Nonnull
protected BackingStore backingStore;
/**
* Instantiates a new {@link BaseCollectionPaginationCountResponse} and sets the default values.
*/
public BaseCollectionPaginationCountResponse() {
this.backingStore = BackingStoreFactorySingleton.instance.createBackingStore();
this.setAdditionalData(new HashMap<>());
}
/**
* Creates a new instance of the appropriate class based on discriminator value
* @param parseNode The parse node to use to read the discriminator value and create the object
* @return a {@link BaseCollectionPaginationCountResponse}
*/
@jakarta.annotation.Nonnull
public static BaseCollectionPaginationCountResponse createFromDiscriminatorValue(@jakarta.annotation.Nonnull final ParseNode parseNode) {
Objects.requireNonNull(parseNode);
return new BaseCollectionPaginationCountResponse();
}
/**
* Gets the AdditionalData property value. Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well.
* @return a {@link Map<String, Object>}
*/
@jakarta.annotation.Nonnull
public Map<String, Object> getAdditionalData() {
Map<String, Object> value = this.backingStore.get("additionalData");
if(value == null) {
value = new HashMap<>();
this.setAdditionalData(value);
}
return value;
}
/**
* Gets the backingStore property value. Stores model information.
* @return a {@link BackingStore}
*/
@jakarta.annotation.Nonnull
public BackingStore getBackingStore() {
return this.backingStore;
}
/**
* The deserialization information for the current model
* @return a {@link Map<String, java.util.function.Consumer<ParseNode>>}
*/
@jakarta.annotation.Nonnull
public Map<String, java.util.function.Consumer<ParseNode>> getFieldDeserializers() {
final HashMap<String, java.util.function.Consumer<ParseNode>> deserializerMap = new HashMap<String, java.util.function.Consumer<ParseNode>>(2);
deserializerMap.put("@odata.count", (n) -> { this.setOdataCount(n.getLongValue()); });
deserializerMap.put("@odata.nextLink", (n) -> { this.setOdataNextLink(n.getStringValue()); });
return deserializerMap;
}
/**
* Gets the @odata.count property value. The OdataCount property
* @return a {@link Long}
*/
@jakarta.annotation.Nullable
public Long getOdataCount() {
return this.backingStore.get("odataCount");
}
/**
* Gets the @odata.nextLink property value. The OdataNextLink property
* @return a {@link String}
*/
@jakarta.annotation.Nullable
public String getOdataNextLink() {
return this.backingStore.get("odataNextLink");
}
/**
* Serializes information the current object
* @param writer Serialization writer to use to serialize this model
*/
public void serialize(@jakarta.annotation.Nonnull final SerializationWriter writer) {
Objects.requireNonNull(writer);
writer.writeLongValue("@odata.count", this.getOdataCount());
writer.writeStringValue("@odata.nextLink", this.getOdataNextLink());
writer.writeAdditionalData(this.getAdditionalData());
}
/**
* Sets the AdditionalData property value. Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well.
* @param value Value to set for the AdditionalData property.
*/
public void setAdditionalData(@jakarta.annotation.Nullable final Map<String, Object> value) {
this.backingStore.set("additionalData", value);
}
/**
* Sets the backingStore property value. Stores model information.
* @param value Value to set for the backingStore property.
*/
public void setBackingStore(@jakarta.annotation.Nonnull final BackingStore value) {
Objects.requireNonNull(value);
this.backingStore = value;
}
/**
* Sets the @odata.count property value. The OdataCount property
* @param value Value to set for the @odata.count property.
*/
public void setOdataCount(@jakarta.annotation.Nullable final Long value) {
this.backingStore.set("odataCount", value);
}
/**
* Sets the @odata.nextLink property value. The OdataNextLink property
* @param value Value to set for the @odata.nextLink property.
*/
public void setOdataNextLink(@jakarta.annotation.Nullable final String value) {
this.backingStore.set("odataNextLink", value);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.function.Consumer;

public class TestEntity implements Parsable, AdditionalDataHolder, BackedModel {
Expand Down Expand Up @@ -107,4 +108,9 @@ public void serialize(@Nonnull SerializationWriter writer) {
// TODO Auto-generated method stub

}

public static TestEntity createFromDiscriminatorValue(@jakarta.annotation.Nonnull final ParseNode parseNode) {
Objects.requireNonNull(parseNode);
return new TestEntity();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.microsoft.kiota;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;


import com.microsoft.kiota.serialization.Parsable;
import com.microsoft.kiota.serialization.ParseNode;
import com.microsoft.kiota.serialization.SerializationWriter;

public class TestEntityCollectionResponse extends BaseCollectionPaginationCountResponse implements Parsable {

/**
* Instantiates a new {@link TestEntityCollectionResponse} and sets the default values.
*/
public TestEntityCollectionResponse() {
super();
}
/**
* Creates a new instance of the appropriate class based on discriminator value
* @param parseNode The parse node to use to read the discriminator value and create the object
* @return a {@link TestEntityCollectionResponse}
*/
@jakarta.annotation.Nonnull
public static TestEntityCollectionResponse createFromDiscriminatorValue(@jakarta.annotation.Nonnull final ParseNode parseNode) {
Objects.requireNonNull(parseNode);
return new TestEntityCollectionResponse();
}
/**
* The deserialization information for the current model
* @return a {@link Map<String, java.util.function.Consumer<ParseNode>>}
*/
@jakarta.annotation.Nonnull
public Map<String, java.util.function.Consumer<ParseNode>> getFieldDeserializers() {
final HashMap<String, java.util.function.Consumer<ParseNode>> deserializerMap = new HashMap<String, java.util.function.Consumer<ParseNode>>(super.getFieldDeserializers());
deserializerMap.put("value", (n) -> { this.setValue(n.getCollectionOfObjectValues(TestEntity::createFromDiscriminatorValue)); });
return deserializerMap;
}
/**
* Gets the value property value. The value property
* @return a {@link java.util.List<TestEntity>}
*/
@jakarta.annotation.Nullable
public java.util.List<TestEntity> getValue() {
return this.backingStore.get("value");
}
/**
* Serializes information the current object
* @param writer Serialization writer to use to serialize this model
*/
public void serialize(@jakarta.annotation.Nonnull final SerializationWriter writer) {
Objects.requireNonNull(writer);
super.serialize(writer);
writer.writeCollectionOfObjectValues("value", this.getValue());
}
/**
* Sets the value property value. The value property
* @param value Value to set for the value property.
*/
public void setValue(@jakarta.annotation.Nullable final java.util.List<TestEntity> value) {
this.backingStore.set("value", value);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static org.junit.jupiter.api.Assertions.*;

import com.microsoft.kiota.TestEntity;
import com.microsoft.kiota.TestEntityCollectionResponse;

import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -422,4 +423,35 @@ void TestsBackingStoreEmbeddedWithMultipleNestedModelsCollectionsAndAdditionalDa

assertEquals(2, invocationCount.get()); // only for setting the id and the colleagues
}

@Test
void TestsBackingStoreUpdateToItemInNestedCollectionWithAnotherBackedModel() {
// Arrange dummy user with initialized backing store
var colleagues = new ArrayList<TestEntity>();
for (int i = 0; i < 10; i++) {
var colleague = new TestEntity();
colleague.setId(UUID.randomUUID().toString());
colleague.setBusinessPhones(Arrays.asList(new String[] {"+1 234 567 891"}));
colleague.getAdditionalData().put("count", i);
colleagues.add(colleague);
colleague.getBackingStore().setIsInitializationCompleted(true);
}

var testUserCollectionResponse = new TestEntityCollectionResponse();
testUserCollectionResponse.setValue(colleagues);
testUserCollectionResponse.getBackingStore().setIsInitializationCompleted(true);

// Act on the data by making a change
var manager = new TestEntity();
manager.setId("2fe22fe5-1132-42cf-90f9-1dc17e325a74");
manager.getBackingStore().setIsInitializationCompleted(true);
testUserCollectionResponse.getValue().get(0).setManager(manager);

// Assert by retrieving only changed values
var changedValues = testUserCollectionResponse.getBackingStore().enumerate();
assertEquals(1, changedValues.size());
assertEquals("value", changedValues.keySet().toArray()[0]);
assertEquals(10, ((List<?>) changedValues.values().toArray()[0]).size());
assertTrue(((TestEntity)((List<?>)changedValues.values().toArray()[0]).get(0)).getBackingStore().enumerate().containsKey("manager"));
}
}

0 comments on commit 51809fa

Please sign in to comment.