-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: generator use only public getters and setters (#2783)
* Use only public getters and setters in generator Fixes: #2587 * Use only public getters and setters in generator Fixes: #2587 * Add integration test --------- Co-authored-by: Anton Platonov <[email protected]>
- Loading branch information
Showing
7 changed files
with
216 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
packages/java/tests/spring/endpoints/frontend/src/test-access-mod.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { html, LitElement } from 'lit'; | ||
import { customElement, query } from 'lit/decorators.js'; | ||
import { AccessModifierEndpoint } from 'Frontend/generated/endpoints'; | ||
|
||
@customElement('test-access-mod') | ||
export class TestAccessModifierComponent extends LitElement { | ||
@query('#content') | ||
private content!: HTMLOutputElement; | ||
@query('#methods') | ||
private methods!: HTMLOutputElement; | ||
|
||
render() { | ||
return html` | ||
<button id="getEntity" @click="${this.getEntity}">Get entity</button> | ||
<output id="content"></output> | ||
<object id="methods"></object> | ||
`; | ||
} | ||
|
||
public async getEntity() { | ||
const entity = await AccessModifierEndpoint.getEntity(); | ||
if (entity === undefined) { | ||
throw new Error('Missing entity object result from endpoint'); | ||
} | ||
|
||
this.content.textContent = JSON.stringify(entity); | ||
this.methods.textContent = Object.keys(entity).join(', '); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
.../tests/spring/endpoints/src/main/java/com/vaadin/flow/connect/AccessModifierEndpoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.vaadin.flow.connect; | ||
|
||
import com.vaadin.flow.server.auth.AnonymousAllowed; | ||
import com.vaadin.hilla.Endpoint; | ||
import jakarta.annotation.security.PermitAll; | ||
|
||
/** | ||
* Simple Vaadin Connect Service definition. | ||
*/ | ||
@Endpoint | ||
@AnonymousAllowed | ||
class AccessModifierEndpoint { | ||
|
||
@PermitAll | ||
public ObjectWithDifferentAccessMethods getEntity() { | ||
return new ObjectWithDifferentAccessMethods("private", "protected", | ||
"public", "package-private", "public-getter", "public-setter"); | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
...ing/endpoints/src/main/java/com/vaadin/flow/connect/ObjectWithDifferentAccessMethods.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package com.vaadin.flow.connect; | ||
|
||
public class ObjectWithDifferentAccessMethods { | ||
private String privateProp; | ||
private String protectedProp; | ||
private String publicProp; | ||
private String packagePrivateProp; | ||
private String publicGetterProp; | ||
private String publicSetterProp; | ||
|
||
public ObjectWithDifferentAccessMethods(String privateProp, | ||
String protectedProp, String publicProp, String packagePrivateProp, | ||
String publicGetterProp, String publicSetterProp) { | ||
this.privateProp = privateProp; | ||
this.protectedProp = protectedProp; | ||
this.publicProp = publicProp; | ||
this.packagePrivateProp = packagePrivateProp; | ||
this.publicGetterProp = publicGetterProp; | ||
this.publicSetterProp = publicSetterProp; | ||
} | ||
|
||
private String getPrivateProp() { | ||
return privateProp; | ||
} | ||
|
||
private void setPrivateProp(String privateProp) { | ||
this.privateProp = privateProp; | ||
} | ||
|
||
protected String getProtectedProp() { | ||
return protectedProp; | ||
} | ||
|
||
protected void setProtectedProp(String protectedProp) { | ||
this.protectedProp = protectedProp; | ||
} | ||
|
||
public String getPublicProp() { | ||
return publicProp; | ||
} | ||
|
||
public void setPublicProp(String publicProp) { | ||
this.publicProp = publicProp; | ||
} | ||
|
||
String getPackagePrivateProp() { | ||
return packagePrivateProp; | ||
} | ||
|
||
void setPackagePrivateProp(String packagePrivateProp) { | ||
this.packagePrivateProp = packagePrivateProp; | ||
} | ||
|
||
public String getPublicGetterProp() { | ||
return publicGetterProp; | ||
} | ||
|
||
private void setPublicGetterProp(String publicGetterProp) { | ||
this.publicGetterProp = publicGetterProp; | ||
} | ||
|
||
private String getPublicSetterProp() { | ||
return publicSetterProp; | ||
} | ||
|
||
public void setPublicSetterProp(String publicSetterProp) { | ||
this.publicSetterProp = publicSetterProp; | ||
} | ||
} |
81 changes: 81 additions & 0 deletions
81
...s/java/tests/spring/endpoints/src/test/java/com/vaadin/flow/connect/AccessModifierIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* Copyright 2000-2017 Vaadin Ltd. | ||
* | ||
* 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 | ||
* | ||
* 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 com.vaadin.flow.connect; | ||
|
||
import com.vaadin.flow.testutil.ChromeBrowserTest; | ||
import com.vaadin.testbench.TestBenchElement; | ||
import org.checkerframework.checker.units.qual.A; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.openqa.selenium.WebElement; | ||
|
||
/** | ||
* Class for testing issues in a spring-boot container. | ||
*/ | ||
public class AccessModifierIT extends ChromeBrowserTest { | ||
|
||
private void openTestUrl(String url) { | ||
getDriver().get(getRootURL() + url); | ||
} | ||
|
||
private TestBenchElement testAccessMod; | ||
private TestBenchElement methods; | ||
|
||
@Override | ||
@Before | ||
public void setup() throws Exception { | ||
super.setup(); | ||
open(); | ||
TestBenchElement testComponent = $("test-component").waitForFirst(); | ||
if (testComponent != null) { | ||
testComponent.$(TestBenchElement.class).id("username") | ||
.sendKeys("user"); | ||
testComponent.$(TestBenchElement.class).id("password") | ||
.sendKeys("user"); | ||
testComponent.$(TestBenchElement.class).id("login").click(); | ||
open(); | ||
} | ||
testAccessMod = $("test-access-mod").waitForFirst(); | ||
methods = testAccessMod.$(TestBenchElement.class).id("methods"); | ||
} | ||
|
||
@Override | ||
protected void open() { | ||
openTestUrl("/access-mod"); | ||
} | ||
|
||
@Test | ||
public void getEntity() { | ||
String endpoint = "getEntity"; | ||
exec(endpoint); | ||
String actualText = waitUntil(driver -> methods.getText(), 25); | ||
Assert.assertNotNull(actualText); | ||
Assert.assertTrue(actualText.contains("publicProp")); | ||
Assert.assertFalse(actualText.contains("protectedProp")); | ||
Assert.assertFalse(actualText.contains("packagePrivateProp")); | ||
Assert.assertFalse(actualText.contains("privateProp")); | ||
Assert.assertTrue(actualText.contains("publicGetterProp")); | ||
// Assert.assertTrue(actualText.contains("publicSetterProp")); // | ||
// property is public, but not present in prototype | ||
} | ||
|
||
private void exec(String id) { | ||
methods.setProperty("innerText", ""); | ||
WebElement button = testAccessMod.$(TestBenchElement.class).id(id); | ||
button.click(); | ||
} | ||
} |